How to copy all from one list of object to another one. Both objects are with the same structure but with different name.
Here is the code:
class Program
{
static void Main(string[] args)
{
List<Test> lstTest = new List<Test>();
List<Test2> lstTest2 = new List<Test2>();
lstTest.Add(new Test { Name = "j", Score = 2 });
lstTest.Add(new Test { Name = "p", Score = 3 });
lstTest2 = lstTest.ConvertAll(x => (Test)x);
}
}
class Test
{
private string name;
private int score;
public string Name
{
get { return name; }
set { this.name = value; }
}
public int Score
{
get { return score; }
set { this.score = value; }
}
}
class Test2
{
private string name;
private int score;
public string Name
{
get { return name; }
set { this.name = value; }
}
public int Score
{
get { return score; }
set { this.score = value; }
}
}
Error that I get is
Cannot implicitly convert type
System.Collections.Generic.List<Test>
toSystem.Collections.Generic.List<cTest2>