Hi Nick, Robert, W, F and all,
Nick I totally agree with your sentiments and reasoning.
However, I do think we need to get used to the LINQ syntax as it is not going to go away, AND, there are places that we will have no choice but use it. It IS very powerful and elegant once we get our heads around it. Which is years for you and me remember.
Like you I did not know why I got into messing with code (attached here) but got a nice one liner to do the task in one go - and two filter clauses as well, one on Key and the other on Value - NICE !
I like the Microsoft preferred LINQ query syntax when it is possible to replace Lambda. Again it is easier to maintain and understand than enumerator loops and stuff.
Oh! - by the way THANKS - you solve my issue I went to bed with and now I know how to apply the 'ToDictionary()' extended method. It works just fine.
Here are three small images of a full test code in X# so others could do similar if they wish.
- Dictionary_11.jpg (106.49 KiB) Viewed 426 times
- Dictionary_12.jpg (118.16 KiB) Viewed 426 times
- Dictionary_13.jpg (108.71 KiB) Viewed 426 times
My big issue yesterday (as always for me) was getting the results of my LINQ query into the correct 'Type' - the resulting collection Type I mean.
Now it works fine with your Googling details.
If I had been able to use intellisense I may have been able to see the requirements for this overload. Still, not bad for working blind ;-0)
Cheers to all,
and yes, I have learned a lot too.
P.S. I will try and send the code - BUT - remember the LINQ namespace requirements as well!
Fingers crossed .........
Code: Select all
local implied oDict := Dictionary<string, string>{}
//--- key, value ---
oDict:Add("txt", "notepad.exe")
oDict:Add("bmp", "paint.exe")
oDict:Add("dib", "paint.exe")
oDict:Add("rtf", "wordpad.exe")
oDict:Add("ybmp", "ypaint.exe")
oDict:Add("zdib", "zpaint.exe")
oDict:Add("artf", "awordpad.exe")
oDict:Add("btxt", "bnotepad.exe")
oDict:Add("cbmp", "cpaint.exe")
oDict:Add("ddib", "dpaint.exe")
oDict:Add("ertf", "ewordpad.exe")
MessageBox.Show(oDict:GetType():ToString(),"Dict type Original :")
oDict := (from d in oDict where d:Key <> "txt" where d:Value <> "paint.exe" select d) ;
:ToDictionary({|r| r.Key}, {|r| r.Value})
MessageBox.Show(oDict:GetType():ToString(),"Dict type Result :")
MessageBox.Show(oDict:Count():ToString(),"Dict count :")