Wednesday 15 February 2012

Another how do I use LINQ to Enumerate Dictionaries -


Thanks for all those who answered and contributed to my previous question. I went to another interesting incarnation of a LINQ question ... so as before ...

I have the following

  const string A_CONVERSATION = "AD channel "; Const String NOT_REPUTABLE = "Advertising Solutions"; Const string DO_NOT_KNOW = "Capture input"; Private Enum Properties {MyHo, Ditches, It} list & lt; String & gt; MyList = new list & lt; String & gt; {A_CONVERSATION, NOT_REPUTABLE, DO_NOT_KNOW} Personal dictionary & lt; Properties, String & gt; PropertyToString; Private dictionary & lt; String, Prozios & gt; StringToProperty;   

How can I use LINQ to populate each dictionary so that I can use the following? Is there a line LINQ statement that will populate each one?

  Properties MyResult1 = Strontopropy [A_CONVERSATION]; String MySResult2 = PropertyToString [properties.It];   

I would like to use the property specifically in the second case.

to provide what you want ...

In two statements (Some mergers may seem to me through some sort of search - but I do not think it was relevant - everything should not be in a line :)

  var properties = ((Properties []) Enum.GetValues ​​(typeof (attribute))). ToList (); Var propertyToString = properties.Zip (MyList, (p, s) => new {prop = p, text = s}). ToDictionary (x => x.Prop, x => x.Text); Var stringToProperty = properties.Zip (MyList, (p, s) = & gt; new {prop = p, text = s}). ToDictionary (x => x.Text, x => x.Prop);   

I have intentionally isolated the structure of the enum list - for clarity - if you wish, you can move it in one line.

No comments:

Post a Comment