c# - How to return a LINQ Anonymoustype to a typed collection -


I am doing LINQ below which I want to return to the collection.

  Var _NewIds.Field from _NewIds in NewIds.AsEnumerable; _OldIds in allOldIds.AsEnumerable () to join; Integer & gt; ("Id") is equal to _OldIds.Field & LT; Integer & gt; ("Id") where _NewIds.Field & LT; Boolean & gt; ("IsExist") == True & amp; Amp; _NewIds.Field & LT; String & gt; Integer & gt; ("Id"), name = _NewIds.Field & LT; String & gt; ("Name"), value = _NewIds ("FIELDNAME") == "FinalValue" new {ID = _NewIds.Field & lt selection .field & lt; Decimal & gt; ("Price")}; & Lt; STD & gt; LstCustomWebsiteVerifiedIndex = New List & lt; Std & gt; ();  

This class is class haivg number, name and value as DataMember.

Any idea how to typecast it? Instead of presenting it for the first time for an unknown class, you need to enter std

  New STD selection {id = _NewIds.Field & LT; Integer & gt; ("Id"), name = _NewIds.Field & LT; String & gt; ("Name"), value = _NewIds.Field & LT; Decimal & gt; ( "cost")};  

And you can do this later:

  list & lt; Std & gt; LstCustomWebsiteVerifiedIndex = StudIds.ToList ();  

But if your class is generated by std some structures (like the unit structure), then you will not be able to use the projection,

In addition, if you can not modify existing code (with anonymous class) , then you can use your query to project in your list such as :

  from the list & lt; STD & gt; LstCustomWebsiteVerifiedIndex = StudIds.Select (r = & gt; New STD {id = r.Id, name = r.Name, value = r.Value,}) .toList ();  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -