View Single Post
  #6 (permalink)  
Old March 23rd, 2005, 11:52 PM
paulie100 paulie100 is offline
Registered User
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

I am interested in this dynamic casting discussion. I have been trying to do it in C# but can't figure out how. Instead of casting using something like

(Int32) y

In my app, I won't know that y is Int32 at coding time. That info will be loaded from a file or a database. So, if the string variable t is set to "Int32" to hold the type of y, I want to be able to do something like

(Type.GetType("System."+t)) y

to cast y to Int32.

I'm guessing you can't do this because it doesn't seem to work when I try (I've tried other variations also), but it seems like there has to be a way. Otherwise how can database programs cast since you often don't know the type of variables until the program runs. I'm a longtime programmer, but fairly new to C# so maybe there is an easy way out that I just don't know.

Thanks for any help.