Up vote 2 down vote favorite share g+ share fb share tw.
So I have a List of Dictionary dict and I want to sort the List alphabetically off the dict"Title" value. How do I go about doing that? And, what if I want to take the value of dict"Title", modify it as string title = dict"Title" + "xyz";, and then use the modified title as the sorting value of that dict (without actually changing dict"Title")... How would I go about doing that as well?
Thanks. C# .net visual-studio silverlight windows-phone-7 link|improve this question asked Mar 9 at 0:27Ethan Allen444211 80% accept rate.
– ahmet Mar 9 at 0:49 Sort on that one "title" key. – Ethan Allen Mar 9 at 0:55.
Linq it: var dicts = new List>(); var sort = dicts. OrderBy(x => x. ContainsKey("Title")?
X"Title" : string. Empty); var sort2 = dicts. OrderBy(x => x.
ContainsKey("Title")? X"Title" + "xyz" : string. Empty).
It seems like you are trying to say something like this: List> list; And what you want to do is something like list.Sort(); But not quite. So, what you can do instead is either make a wrapper class for Dictionary and then overload the compare methods, or you could make a comparison method like static int CompareDicts(Dictionary x, Dictionary y) { return String. Compare(x"Title",y"Title"); } or static int CompareDicts(Dictionary x, Dictionary y) { return String.
Compare(x"Title"+"xyz",y"Title"+"xyz"); } And then to sort list. Sort(CompareDicts); Edit: For a bunch of Sort functions on a List, check out http://msdn.microsoft.com/en-us/library/3da4abas.aspx.
LINQ is the solution here. Dictionary. OrderBy(o => o.
Key) dictionary. OrderByDescending(o => o. Key) And for the modified version dictionary.
OrderBy(o => o. Key + "xyz") dictionary. OrderByDescending(o => o.
Key + "xyz").
This sorts a Dictionary, not a List> – Michael Edenfield Mar 9 at 1:06 Oops, misread the question. – SwearWord Mar 9 at 5:09.
Var dicts = new List>(); // populate dictionaries. Var sorted = dicts. OrderBy(x => x.
ContainsKey("Title")? X"Title" : string. Empty)).
For his second modified Title: var sort2 = dicts. OrderBy(x => x. ContainsKey("Title")?
X"Title" + "xyz" : string. Empty); – Beyers Mar 9 at 1:20.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.