Using linq, what is the easiest way to conv list <long> for list <int>?
4 answers
UPDATE : as some commentators note, the following answer is incorrect. As stated in the docs ,
If an item cannot be discarded for TResult input, this method will be an exception.
I suspect, but now I canβt verify that this means that everything that can be implicitly (for example, from int to long or a subtype to a supertype) will work, and everything else will throw an exception. In particular, even explicit casts (e.g., from long to int ) will fail.
/ UPDATE
You need to be aware of the possibility of data loss, as some of the lengths may have value outside the range supported by int.
List<long> a = new List<long>(); List<int> b = a.Cast<int>().ToList(); +4