Create List<int> with values at compile time
List<int> myValues = new List<int>(new int[] { 1, 2, 3 } );
This will create an intermediate array however so there may be a more efficient way of doing the same thing.
EDIT:
John Feminella suggested creating a factory method to accept a list of parameters and return a List which you could implement as follows:
List<T> CreateList<T>(params T[] values)
{
return new List<T>(values);
}
which you can use as follows:
List<int> myValues = CreateList(1, 2, 3);
Patrick has the answer you are looking for. But I wanted to add a little bit. If you want to do longer ranges of numbers and don't feel like typing them out by hand, you should look at the Enumerable.Range method. It can be used to generate a range of sequential numbers at runtime. For instance, your sample could have been written as follows
var list = Enumerable.Range(1,3).ToList();
The way you suggests was first introduced in C# 3.0 (has nothing to do with LINQ, it was a language feature that was introduced).
There's no "shortcut" (list initialization) in C# 2.0 to do just that, either new up the list and then add the numbers manually via myValues.Add, or you could do the following:
int[] arrMyValues = new int[] {1, 2, 3};
List<int> myValues = new List<int>(arrMyValues);
List of T can take an IEnumerable of T in it's constructor, of which it'll include all T's in that IEnumerable in the list created, seeing as int[] implements IEnumerable of T you can "mix and match" the features like so.
Besides that, there's no way in C# 2.0 to do a such thing that you describe.