Try this instead:
foreach (var x in Enumerable.Range(0, 3)) {
lst.Add(x.ToString());
}
The .Select()
method is for projecting/mapping from one set of values to another, so the function that you pass to it need to return a value. In your case you're returning an anonymous object (i.e. new { }
) but you're calling lst.Add()
inside the body of the object which is a syntax error.
You could also do it in one line like this:
List<string> lst = Enumerable.Range(0, 3).Select(x => x.ToString()).ToList();