c# - Is it possible to get other collection than IEnumerable<T> when using LINQ: XML to object? -


Then I have this big XML file that I am converting an object using LINQ. And currently I am:

Results from the results result in XML.Descendants ("story") select the new newsletter {paragraphFire =) from the tag in the story. ("Tag") Select new key wallpier and lieutenant; String, At & G; (String) tag. Element ("name"), (int) tag. Element ("count")}}

From now on, give me a IEnumerable & lt; KeyvaluePair & lt; String, int & gt; & Gt; creates or list & lt; New MyItem (string key, int value) P>

I have this huge LINQ is a book and it contains only information about objects for XML.
This question relates to the XML object.

Thanks

Yes, it is possible using the Linqs method.

You should be able to say

  ArticleFrequency = (from the tag in the story. Descendants ("tag") Select the new {key = (string) tag. ("Name"), value = (int) tag.Element ("count")}). (Val = & gt; val.Key, val = & gt; val.Value)  

Your article frequency property should definitely be of type < Code> idictionary & lt; String, At & G;

UPDATE to answer your question in S (if I understand correctly), just to calculate the desired type, like

  ArticleFrequency = (Choose the new MyCustomObject) (MyPropertyOne = (string) tag.Element ("name"), MyPropertyTwo = (int) tags from tags in the story. .Element ("count")})  

A IEnumerable & lt; MyCustomObject & gt; If you are saying that you want article fractures to be type stacked, you can wrap the entire link query and use it as an example IEnumerable parameter like < / P>

  ArticleFrequency = new stack & lt; KeyValuePair & lt; String, int & gt; & Gt; (From the tag in the story. Residual ("tag") New kyalpeare & lt; string, int & gt; () {key = (string) tag. Element ("name"), value = (int) tag.Allement ( "Count")}))  

Comments