Timeline for Sorting a list with respect to another list
Current License: CC BY-SA 3.0
17 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 9, 2013 at 7:51 | comment | added | Steve B | @siva: You may succeed in synchronizing the sort operation by defining a new list of indexes, then reorder all the lists following these indexes. But it will be quite complex, hard to read and high potential of bug. So I highly suggest you to model your data with classes, like I showed in my answer. Do you see anything wrong with my approach? It's true you will have to refactor your code to match the new object model, but I bet this will be far more easier and less risky than continuing in the direction you are talking about. Give a try ;) | |
| Jul 9, 2013 at 5:41 | comment | added | Siva | @SteveB i am fully confused. i doesn't change my devicelogdata. i want use as it is. but when i sort the time list then all other list to be sorted with respect to time list. how can i achieve this. can u please help me.. | |
| Jul 8, 2013 at 15:37 | comment | added | Steve B | @Servy: I added a small code snippet related to your last comment. Feel free to edit the post if I was wrong. | |
| Jul 8, 2013 at 15:36 | history | edited | Steve B | CC BY-SA 3.0 | added 675 characters in body |
| Jul 8, 2013 at 15:22 | history | edited | Servy | CC BY-SA 3.0 | deleted 3 characters in body |
| Jul 8, 2013 at 15:03 | comment | added | Servy | Note that List.Sort has an overload that takes a comparer delegate, in the event that mutating the list rather than returning a sorted sequence is needed. | |
| Jul 8, 2013 at 14:47 | comment | added | Steve B | Hum... I may have confused with another class. Apologize. I've updated the code to answer with something that compiles. | |
| Jul 8, 2013 at 14:46 | history | edited | Steve B | CC BY-SA 3.0 | added 169 characters in body |
| Jul 8, 2013 at 14:35 | history | edited | Steve B | CC BY-SA 3.0 | deleted 94 characters in body |
| Jul 8, 2013 at 14:22 | comment | added | Servy | @SteveB Well, that and SortedList doesn't have a constructor that accepts delegates, so this code won't even work. The point was you went out of your way to change the code the OP was using (which was a list that he called Sort on) to a SortedList. Just leaving the code that he had, and using a List, would be better in quite a number of ways, including, among other things, performance. | |
| Jul 8, 2013 at 14:17 | comment | added | Steve B | @Servy: does it matter? The idea of my answer was to highlight the creation of a custom object. The SortedList is completary to simplify the sorting requirement. Maybe there are faster collections, lower memory consumption collections, etc. But as there is no "realtime" or heavy requirement mentioned, I can live with that. Feel free to add extra link for more advanced users. | |
| Jul 8, 2013 at 14:13 | comment | added | Steve B | @Henrik: yeas, I missed the first generic argument. Thanks | |
| Jul 8, 2013 at 14:12 | history | edited | Steve B | CC BY-SA 3.0 | added 10 characters in body |
| Jul 8, 2013 at 14:03 | comment | added | Servy | It's actually more efficient to add the items to a List and then sort it than to add the items to a SortedList. SortedList is, in most cases, inferior to another collection for any particular task. I've almost never found it to be the best collection for any given job. | |
| Jul 8, 2013 at 13:54 | comment | added | Henrik | Are you talking about System.Collections.Generic.SortedList<TKey, TValue>? | |
| Jul 8, 2013 at 13:43 | history | edited | Steve B | CC BY-SA 3.0 | added 17 characters in body |
| Jul 8, 2013 at 13:38 | history | answered | Steve B | CC BY-SA 3.0 |