TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
bonehead
NA
7
1.2k
How to Convert string[] to eg int32[]
Jan 23 2013 4:20 PM
Hi,
Getting invalid cast exception, when casting from string to int32[]. What's the correct approach to casting below.
Thanks.
int[] ii = ReadField<int[],string>("Col5", "Game", "Who");
static T ReadField<T,U>(string searchCol, U searchFor, string colName)
{
Type u = typeof(T);
string[] foundValues = "4,9".Split(',');
Array a = Array.CreateInstance(u, foundValues.Lenght);
for (int i =0; i < foundValues.Lenght, i++)
a.SetValue(Convert.ChangeType(foundValues[i], u), i); <== Incorrect cast string to int32[]
return ?? (T)Convert.ChangeType(a, u);
}
Reply
Answers (
5
)
Copying column data from ListView1 to ListView2 - help!
How to set countdown to time from public string function?