Pepe
Pepe

Reputation: 111

Convert anonymous type list to normal list

I have a simple model like:

public class MyDataClass
{
    public Guid Value1 { get; set; }
    public Guid Value2 { get; set; }
}

Then I have anonymousTypeList like:

var parameterstest = assignNotificationTableType
                       .Select(x => new { TaskId, x.EmpGuid })
                       .ToList();

So I want to convert that anonymous type list to a normal list so I try:

List<MyDataClass> lista = new List<MyDataClass>();
foreach(var i in parameterstest)
{
    lista.Add(i.TaskId,i.EmpGuid);
}

But I get

Error CS1501 No overload for method 'Add' takes 2 arguments

Upvotes: 0

Views: 139

Answers (1)

Daniel A. White
Daniel A. White

Reputation: 190943

You can use it simply:

var parameterstest = assignNotificationTableType
                   .Select(x => new MyDataClass { Value1 = TaskId, Value2 = x.EmpGuid })
                   .ToList();

Upvotes: 9

Related Questions