I've declare a anonymous list like this, and it contain list of contact also
var ContactGroup = new[] { new { ContactGroupKey = 0, ContactGroupTLK = 0, Desc = "", Contacts=new List<object>() } }.ToList();
I try to check the list, if the ContactGroupKey is exists then update only the Contacts(defined as a list) else insert a new contactgroup. but when i tried to add a new contactgroup inside my anonymous list its throw an error "The best overloaded method match for 'System.Collections.Generic.List.Add(AnonymousType#2)' has some invalid arguments " I'm using anonymous list first time. I tried to avoid classes in this scenario. can any one suggest me where i made the mistake?
while()
{
var Contact= new {
ContactKey = Convert.ToInt64(DB["ContactKey", "0"]),
FirstName = DB["FirstName", ""].ToString(),
Surname = DB["Surname", ""].ToString(),
FullName = DB["Fullname", ""].ToString(),
Street = DB["bStreet", ""].ToString(),
City = DB["bCity", ""].ToString(),
};
foreach (var item in ContactGroup)
{
if (item.ContactGroupKey == Contact.ClaimContactGroupKey)
{
item.Contacts.Add(Contact);
added = true;
}
}
if(!added){
ContactGroup.Add(new {
ContactGroupKey = Convert.ToInt64(DB["ContactGroupKey", "0"]),
ContactGroupTLK = Convert.ToInt64(DB["TranslationKey", "0"]),
Desc = DB["Description", ""].ToString(),
Contacts=GenerateList(Contact)
});
}
}// End While
public static List<T> GenerateList<T>(T itemOftype)
{
List<T> newList = new List<T>();
return newList;
}