Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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..

Sun Certified Web component Developer,

Microsoft Certified Solution Developer .NET,

Software Engineer

Posted
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.
Posted

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

Sun Certified Web component Developer,

Microsoft Certified Solution Developer .NET,

Software Engineer

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...