goodmorningsky Posted September 13, 2005 Posted September 13, 2005 Hi, all. I have string array. I want to convert a specific type. I need following like method. /// Convert string array to specified type array public static object ConvertArrayType(string[] inputArr, System.Type itemType){} I want to do like this. return (itemType[]) inputArr; //I know this is wrong. However this give you idea what I try to do. :p Is there a method/Reflection alreay doing this or it's not possible? Thank you all.. Quote Sun Certified Web component Developer, Microsoft Certified Solution Developer .NET, Software Engineer
bri189a Posted September 13, 2005 Posted September 13, 2005 Well if these aren't native types you'll have to do some reflection to make sure that the type you're trying to convert from can be converted to the specified type (use IConvertible). Then I'd simply make a loop and through each original item and use the ToType method of the IConvertible interface and assign that to the same indexed item of the new item. Quote
goodmorningsky Posted September 13, 2005 Author Posted September 13, 2005 I want to use premitive types too. I want to define it once and reuse it since I have to use it alot. And I feel it's possible, but don't know... :p Quote Sun Certified Web component Developer, Microsoft Certified Solution Developer .NET, Software Engineer
bri189a Posted September 13, 2005 Posted September 13, 2005 I think if you follow what I have above you should be able to make one. I could of swore there was a native way to do it, but I can't seem to find it now. Maybe someone else will chime in with the answer. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.