Friday 7 July 2017

System.Collections.Generic.List'1[System.String]

I had used to store the List of items in object

i.e.,

var contactAddress = contact.AddressInformation.Where(x=>x.AddressInformation.AddressType.AddressTypeId==(int)contantEnumeration.AddressType.PrimaryAddress).Select(x=>x.AddressInformation.Address1).ToList();

In the above code, we are using to retrieve single data(element) from List of object and converting in to List by using .ToList(), so that it is unable o store single data(element) in to List,
So it is storing "System.Collections.Generic.List'1[System.String]".

I removed .ToList() from above code, then it is storing {System.Linq.Enumerable.WhereSelectEnumerableIterator<Application.Model.DataDomain.ContractAddress,String>}

Because the type conversion is not there and unable to store exact value to retrieve the single record data from the list.

So we have to use .FirstOrDefault() to view the expected data in the variable.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.