type-casting

Typecasting based on a variable

How would I go about the following... I have a control that can be bound to different data types... String, Int, Int32, DateTime, etc... but generically the result is stored into a generic "object" data type. So, I use another field to identify the EXPECTED type such as.. String BoundDataType = "System.String" // or System.Int32 or ...

Efficient way to convert strings from split function to ints in Python

I have a string of data with the following format: xpos-ypos-zoom (i.e. 8743-12083-15) that I want to split up and store in the variables xpos, ypos, and zoom. Since I need to do some calculations with these number I'd like to convert them to integers right from the beginning. Currently, the way I'm doing this is with the following code:...

DirectCast not accepting valid casts at compiletime (VB.NET)

How come this is not a valid DirectCast: Public Sub FB(OF T0 As IGH_Goo, T1 As IGH_Goo) _ (ByVal A As DataTree(Of T0), _ ByVal B As DataTree(Of T1)) Dim val_A As T1 = DirectCast(A.FirstItem, T1) End Sub whereas this is: Public Sub FB(OF T0 As IGH_Goo, T1 As IGH_Goo) _ (ByVal A As DataTree...

print the float value in integer in C language

#include<stdio.h> int main() { float a=5; printf("%d",a); return 0; } This gives the output: 0 Why is the output zero? ...

how can convert LPCSTR string into LPCTSTR string?

i am trying to convert a LPCSTR string into LPCTSTR string. i want to concatenate two string,when i try like this LPCTSTR str1 = L"Raja" LPCSTR str2 = "Kumar" wcscat_s(str1,(LPCTSTR)str2); i found the o/p like Raja....r(junkvalues)....how can typecast LPCSTR to LPCTSTR? ...

What is the difference between (type)value and type(value) ?

What is the difference between (type)value and type(value) in C++? ...

Casting JSON/XML in AS3

Having used FlashDevelop with a project, and switched to FDT/Eclipse. I am sorting through hundreds of warnings in my code. Quite a few relate to XML and JSON syntax this project is using. In the following, I'm not sure what to cast the XML containing data as so that it is recognised by the compiler Example: public function convertXML...

C# Typecast Basic querry

Hi I am new to C# I have a struct like struct Package { Public int[] intvalues; Public char[] charvalues; Public string strvalue; } Now I have a string string strquery; I want to take the value of intvalues of the Package whose name is strquery. As far as I tried, this didnt work (Package)strquery.strvalue Please help ...

Type Casting C++

see the following code: void simple_dynamic_casts( ) { AB ab; B* bp = (B*)&ab; // cast needed to break protection A* ap = &ab; // public derivation, no cast needed AB& abr = dynamic_cast<AB&>(*bp); // succeeds ap = dynamic_cast<A*>(bp); assert( ap != NULL ); bp = dynamic_cast<B*>(ap); assert( b...

Casting generic object array to two types

I've got a method that receives an Object[] and then performs actions on that array. At first I was passing in this array as an IEnumerable<T> however the T can be of two different types. The T's will always have the same properties, even thought they're different types. Is it possible to cast to a a type at runtime so that I can use...

Find out Type of C++ Void Pointer

Hello, I have a small question: how do I find out what type a C++ pointer is? I often use a small function in my console programs to gather input, which looks something like this: void query(string what-to-ask, [insert datatype here] * input) I would like to create a generic form, using a void pointer, but I can't cin a void pointer,...

Why do I need to type-cast an object when sending it an "isKindOf:" message?

If I'm trying to find out if an object is a type of a certain class (or any of that class's descendants), it seems that I should use "isKindOf:" if ([foo isKindOfClass:[bar class]]) {...} But the compiler gives me a warning "invalid receiver type 'void *'". This goes away if I cast "foo" to NSObject...or any other class! No matter w...

VB.NET Conversion problem when trying to convert from base class to subclass (BC30311: "Value of type '<type1>' cannot be converted to '<type2>'")

Hello! Please take a look at the following code: Public Sub Method(Of TEntity As EntityObject)(ByVal entity As TEntity) If TypeOf entity Is Contact Then Dim contact As Contact = entity 'Compile error' Dim contact = DirectCast(entity, Contact) 'Compile error' Dim contact = CType(entity, Contact) 'Compile er...

Delphi: generics and 'is'-operator problem

Based on an earlier post, I've written the following code. Please excuse the verbosity of this post. I believe it's better for all parties to have the full code available to test and comment on. program sandbox; {$APPTYPE CONSOLE} uses SysUtils, Generics.Collections; type TDataType = class // Stuff common to TInt and TStr ...

Cast boost::shared_array<char> to boost::shared_array<const char>

How can I cast a boost::shared_array<char> to boost::shared_array<const char>? ...

Haskell: How to type cast

C#: static int F(object x) { return x is string ? 1 : 2; } Haskell? The tricky bit seems to me that Haskell does not have a root type object. Edited: I do not care about converting to string. I want to know how to typecast (for example to see if an object is a Customer or an Order. ...

Check for the right typecasting

Is there a safer way to typecast data from a generic pointer.? More specifically , is there a way to check if the type casting is safe or not. Suppose void*data we receive from the recv function in netwrking code. Suppose there are two structures: struct data1 { int val; double val1; } struct data2 { char str[100]; long double val3;...

c++ typecast array

How can one typecast an array of int to an array of float? Thanks. ...

InvalidCastOperation Exception - can't find what's wrong

I have the following two methods, and the last one throws an InvalidCastOperationException, I cannot see what is wrong. public static ArrayList GetEmployeesArrayList() { ArrayList al = new ArrayList(); // do some work here... return (al); } public static Employee[] GetE...

typecasting bigger or smaller structure in C

I have two structures in C program: SmallStructABC and BigStructXYZ I have several members in both of them; SmallStructABC's all 10 members are exactly same as first 10 members of BigStructXYZ. BigStructXYZ has 50 additional members. Is it OK to type-cast this two structures to each other? SmallStructABC *i = (BigStructXYZ*)j; BigStr...