How do you split a string to a List? I'm looking for the equivalent of ToCharArray but instead to make it a List.
string data = "ABCDEFGHIJ1fFJKAL";
List<string> datalist = new List<string>();
datalist.AddRange(new List<string>{"A","B","C"});
How do you convert data so it will be accepted by AddRange?
If you want a list of characters, then you would use a
List<char>
rather thanList<string>
, and then you don't have to do anything at all to the string. TheAddRange
method takes anIEnumerable<char>
and theString
class happens to implementIEnumerable<char>
:If you want a
List<string>
to hold the characters anyway, then you would need to convert each character to a string: