Sunday 15 February 2015

c# - IEnumerable to Dictionary<char, IEnumerable> -


I think this question can partly mimic other similar questions, but I have trouble with such a situation

For example,

"string sentence =" we want to remove these characters individually We can also check against other string characters. ";

I want to create an IEnumerable word;

  var separators = new [] {',', '', '.'}; IEnumerable & LT; String & gt; Word = sentence Sample (Separator, String Split Option. RemoveEmptyEntries); After that, press all these  words  and take the characters of the characters in a different ascending sorted collection.  
  var firstchurch = word Selection (x = & gt; x.ToCharArray (). First ()). Serial (x = & gt; x). Undoubtedly ();   

Then, both codes and words for all characters in the items by words Get it. In which the first letter is equal to current character and a dictionary & lt; Char, IEnumerable & lt; String & gt; & Gt; Dictionary .

I am doing this way:

  var dictionary = (words from k in the first words where v.ToCharArray (). () .Equals ( K) Select new {k, v}). ToDictionary (x => x);   

And here's the problem: An item with the same key has already been added. Whis because it is adding an existing character to that dictionary

I have included a GroupBy extension in my query

  var Dictionary = (In the first words from k to words in v.ToCharArray () first (). Select equals (k) new {k, v}) .GroupBy (x => x). ToDictionary (x => x);   

The solution given above all cures, but this requires me the other way. I

 Enter image details here What should I do to get the result < but not dictionary & Lt; IGouping & lt; One, 'A & gt; & Gt; dictionary dictionary & lt; Char, IEnumerable & lt; String & gt; & Gt;

The result that I want is in the form of an image: Enter image details here But here I have to be repeated with two foreach (s) which will show me the watt which I want ... I can not understand how this happens ...

Any suggestions and advice Thank you.

You can:

  var word = .. . Var dictionary = words.GroupBy (w = & gt; w [0]). ToDictionary (g = & gt; g.Key, g = & gt; g.AsEnumerable ());   

But for the case, why not use it?

  var lookup = words.ToLookup (w = & gt; w [0]);    

No comments:

Post a Comment