Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert list<int> to list<long>

Tags:

c#

list

generics

How to convert List<int> to List<long> in C#?

like image 880
sakthi Avatar asked Jul 21 '10 02:07

sakthi


People also ask

How to convert List types c#?

The recommended approach to convert a list of one type to another type is using the List<T>. ConvertAll() method. It returns a list of the target type containing the converted elements from the current list.

How do I convert a list of numbers to a string in Python?

To convert a list to a string, use Python List Comprehension and the join() function. The list comprehension will traverse the elements one by one, and the join() method will concatenate the list's elements into a new string and return it as output.

How do I convert an int to a string in C#?

Converting int to string in C# is used to convert non-decimal numbers to string character. This can be done by using int to string conversion, int to string with Int32. ToString(), int to string with string concatenation, int to string with StringBuilder, int to string with Convert.


1 Answers

Like this:

List<long> longs = ints.ConvertAll(i => (long)i);

This uses C# 3.0 lambda expressions; if you're using C# 2.0 in VS 2005, you'll need to write

List<long> longs = ints.ConvertAll<int, long>(
    delegate(int i) { return (long)i; }
);
like image 71
SLaks Avatar answered Sep 30 '22 03:09

SLaks