Using link what is the easiest way to convert a list of longs to a list of ints?
I need it to be a list, if it cant be possibly i would like to see a solution with a int array or some kind f int container.
Using link what is the easiest way to convert a list of longs to a list of ints?
I need it to be a list, if it cant be possibly i would like to see a solution with a int array or some kind f int container.
You need to be aware of the possibility of data loss since some of the longs may have a value outside the range supported by an int.
List<long> a = new List<long>();
List<int> b = a.Cast<int>().ToList();
var myIntList = myLongList.Select(x => (int)x).ToList();
Doesn't handle long
values larger than int
can hold correctly, although there's not really any way around that.
You dont need LINQ. Simply do:
List<int> intlist = longlist.ConvertAll(x => (int)x);
If you really do want LINQ:
var intlist = longlist.Select(x => (int) x).ToList();