How to copy array string to <string> list?
Possible duplicate:
Convert an array of strings to a <string> list
I'm new to C # How to copy the entire array string to a list?
I tried this, but I did not get any solution.
List<string> lstArray = strArray.toList<string>; or List<string> lstArray = new List<string>(); strArray.copyTo(lstArray,0); +6
2 answers
Skip the array of strings in the constructor list.
List<string> yourList = new List<string>(strArray); The reason your first line is not working is because you are not using the correct syntax. Therefore, instead of
List<string> lstArray = strArray.toList<string>; Using
List<string> lstArray = strArray.ToList<string>(); or
List<string> lstArray = strArray.ToList(); // with less keystrokes, since the array is of type string. For the second option, where you are trying to use Array.CopyTo, it works with array types, not a general list. You are probably getting an error.
The best overloaded method match for 'System.Array.CopyTo (System.Array, int)' has some invalid arguments
Since it expects an array, and you pass a general list.
+15