Problem is simple and I am looking for a simple solution. I am having a class with single member like
public class Test
{
public int TestInt{get; set; }
}
List <Test> intList = new List<Test>();
and a list like
List <int> lstNumber
I want to do something like
intList = lstNumber
. ``
I know I can do it using foreach statement but wondering as the class is just having one member i.e. too integer, is there is anyway I can convert it directly by using something like Linq. I am just a beginner programmer in C# so would really appreciate any help
This should work. You can create a new instance of Test
for each integer in lstNumber
.
var intList = lstNumber.Select(x => new Test{ TestInt = x}).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With