Convert string to List<string> in one line?

Brian David Berman picture Brian David Berman · Feb 16, 2011 · Viewed 255.8k times · Source

I have a string:

var names = "Brian,Joe,Chris";

Is there a way to convert this to a List<string> delimited by , in one line?

Answer

Matt Greer picture Matt Greer · Feb 16, 2011
List<string> result = names.Split(new char[] { ',' }).ToList();

Or even cleaner by Dan's suggestion:

List<string> result = names.Split(',').ToList();