What's the correct C# syntax to do the following using sexier syntax?
string[] arr = ///....
List<string> lst = new List<string>();
foreach (var i in arr) {
lst.Add(i);
}
I feel like this could be a one liner using something like: arr.Select(x => lst.Add(x));
but I'm not quite bright enough to figure out the right syntax.
.ToList() is fine, but to be honest, you don't need LINQ for that:
List<int> list = new List<int>(arr);
List<string> lst = arr.ToList();
http://msdn.microsoft.com/en-us/library/bb342261.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With