In Java, I can assign a value from Vector to a String variable.
String str = vector1.elementAt(0).toString();
How can I do the same thing in C# with List?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are many ways to do this:
Assuming
Then all of the following would put the element in position
indexinside a string variable:string s = yourList[index];string s = yourList.ToArray()[index];string s = yourList.ElementAt(index);In all of the above,
indexmust fall within the range0 - (yourList.Length-1)since array indexing in C# is zero-based.This, on the other hand, while it would seem the same, won’t even compile:
string s = youList.Skip(index).Take(1);.Take()in this case doesn’t return astringbut aIEnumerable<string>which is still a collection.