.NET converting simple arrays to List Generics

Use:

using System.Linq;

string[] strList = {'foo','bar','meh'};
List<string> listOfStr = strList.ToList();

If you reference System.Linq, you can type:

string[] strList = {'foo','bar','meh'}; 
List<string> listOfStr = strList.ToList(); 

exactly like you want to.

The second syntax should also work.


object[] array = new object[10];
List<object> list = array.ToList();

Method ToList is linq method. You need to add

using System.Linq;

If I understand your question correctly, one of the code segment you have will work. In C#, string needs to be enclosed in double quote, not single.

string[] strList = {"foo","bar","meh"};
List<string> listOfStr = new List<string>(strList);