casting

WCF and Object

I am trying to pass an object into a WCF web service, the object I am passing in is a Server object, I then want to be able to call TestConnection(); The issue I am having is that Server is the base class and there are several derived classes of Server, i.e. SqlServer2005Server, OracleServer and ODBCServer that I want to use I want to ...

Downcasting and Linq

Hi, I have a base class called LabFileBase. I have constructed a List and have added my derived classes to it. I want to search the List for a particular object based on a key I've defined. The problem I'm having is how do you downcast in a LINQ expression? Here is some sample code: public abstract class LabFileBase { } public cla...

How do I correctly cast an item in a DataSet when it can potentially be null?

I have a dataset being returned by a stored proc and one of the items in it can potentially be null. I'm trying to convert each row in the dataset to a strongly typed object but I can't seem to cast the null value properly. I've created a mock up of my scenario as follows: DataSet ds = new DataSet(); ds.Tables.Add(new DataTable()); ds....

How can I avoid code duplication with many small classes?

I have different classes called English, Spanish, French, etc.: Class English{ String name = "English"; String alias = "ENG"; } Class French{ String name = "French"; String alias = "Fre"; } Similarly other language classes. And one more class called Language: Class Language{ String name = ""; String alias = ...

C#: How can I use implicit cast operator during object to type conversion?

HI! Here is my case: I have some value type which is wrapped into another type with appropriate implicit converters. If I cast wrapped type to an object and then try to get original value I can do that in two-step cast only. If simplified my code is as follows: public enum MyEnum : int { First, Second } public class Test<T> ...

How can I cast a list using generics in Java?

Please consider the following snippet: public interface MyInterface { public int getId(); } public class MyPojo implements MyInterface { private int id; public MyPojo(int id) { this.id = id; } public int getId() { return id; } } public ArrayList<MyInterface> getMyInterfaces() { ArrayLi...

Single method for multiple types?

In cases where you have a function that works for many different custom types with the same implementation, is it ok to use a design pattern like this?: type1 implicitly casts to type0 type2 implicitly casts to type0 type3 implicitly casts to type0 Operate ( type0 ) and call: type1 a type2 b type3 c Operate ( a ) Operate ( b ) Oper...

Comparing String to Integer giving strange feedback

I'm really confused as to why this operation works. Can someone explain it? $test1 = "d85d1d81b25614a3504a3d5601a9cb2e"; $test2 = "3581169b064f71be1630b321d3ca318f"; if ($test1 == 0) echo "Test 1 is Equal!?"; if ($test2 == 0) echo "Test 2 is Equal!?"; // Returns: Test 1 is Equal!? For clarification, I am trying to compare the s...

.NET Casting Generic List

Can someone explain to me why in .NET 2.0 if I have an interface, IPackable and a class that implements that interface, OrderItem, when I have a method that takes in a List, passing in a list of List does not work? Does anyone know how I could accomplish this functionality? Thanks Josh Code: public interface IPackable { do...

Performance hit from C++ style casts?

I am new to C++ style casts and I am worried that using C++ style casts will ruin the performance of my application because I have a real-time-critical deadline in my interrupt-service-routine. I heard that some casts will even throw exceptions! I would like to use the C++ style casts because it would make my code more "robust". Howeve...

What does casting do at compiler/machine level?

I have often wondered what exactly does casting do at compiler or machine level. What does it do with the 0 and 1s in memory? Can anyone point me at some good literature. ...

Type casting in VB .NET

I am adding a feature to an existing VB .Net application that involves retrieving data from a .Net web service. The web service returns an array of Locations. A Location is pretty simple, it has 3 properties – an integer and two strings. So that the rest of my application does not have to be dependent on this web service, I would li...

Best way to store UInt32 in Sql Server

Hello, I'm working on an application that uses a third-party component, and this component returns a value that is of type UInt32. I need to store this UInt32 in a Sql Server table. I was thinking about just use a simple int column and insert the value like this: int value = (int)(cs - int.MaxValue); But I'm not sure if this is the b...

Avoiding casting when passing objects through library code (In Delphi)

When designing libraries, I often end up resorting to the following pattern, which I don't like as it results in lots of type-casting. The basic pattern is: The code using the library hands an object to the library, the library then hands the object back to the calling code. The calling code is forced to cast the object, as the library ...

String casts

Hi Why is there so may ways to convert to a string in .net? The ways I have seen are .ToString, Convert.ToString() and (string). What is the Difference. ...

Convert an array of objects

how can i convert from: object[] myArray to Foo[] myCastArray ...

WPF: Correctly storing an object in a TreeViewItem

To store an object (say, an instance of a class) in a TreeViewItem, I am currently storing the object in the TreeViewItem's Header and then overriding the ToString method of that class, so that it displays the correct string header; I then cast the object back during an event. Is this the correct way to achieve this sort of thing, or ...

can I cast an object to it's generic type in C#?

Sorry to ask this yet again. I've been reading the related topics here for hours and still don't quite get some of the issues with casting and generics. I'm trying to create our own HashSet class, because we can't use .net 3.5 yet. The error is in the RetainAll method, below. It compiles fine but I get a runtime error 'Unable to cast...

Converting (void*) to std::vector<unsigned char>.

I have a (void*) buffer that I need to convert to std::vector<unsigned char> before I can pass it on. Unfortunately, my C++ casting skills a little weak. Any suggestions? ...

Overriding (cast)

If I have a base class and two derived classes, and I want to implement the casting between the two derived classes by hand, is there any way to do that? (in C#) abstract class AbsBase { private int A; private int B; private int C; private int D; } class Imp_A : AbsBase { private List<int> E; } class Imp_B : AbsBase { ...