Strange List<string> sorting request</string>
-
Is it possible to sort a generic list base don the sort of another generic list? Here is what I am working with: I have a List object that I built out of a List, where the strings in the first list are populated with a specific string property from the second. so, say this is my example, the List<Q_object> object is made up of this: lets say Q_object has the follwing properties: string str1 string str2 int i and my objects in the list are specifically: Q_object[0] has str1 = "fudge"; str2 = "brownie"; i = 0; Q_object[1] has str1 = "Beer"; str2 = "Sausage"; i = 1; Q_object[2] has str1 = "Pancakes"; str2 = "waffles"; i = 2; now, the List has the following: "Sausage" "brownie" "waffles" essentially, somwhere along the line, the list got out of order. Now, I need it to be in the original order, but it has to be the string list as opposed to me trying to access the properties of each individual object in the original list. is there a way to say "sort List to match List's properties with the same values"? I'm thinking Linq has my answers, but I dont know for sure, and I dont know where to begin. Any suggestions would be appreciated :)
______________________ Oh Hamburgers!
-
Is it possible to sort a generic list base don the sort of another generic list? Here is what I am working with: I have a List object that I built out of a List, where the strings in the first list are populated with a specific string property from the second. so, say this is my example, the List<Q_object> object is made up of this: lets say Q_object has the follwing properties: string str1 string str2 int i and my objects in the list are specifically: Q_object[0] has str1 = "fudge"; str2 = "brownie"; i = 0; Q_object[1] has str1 = "Beer"; str2 = "Sausage"; i = 1; Q_object[2] has str1 = "Pancakes"; str2 = "waffles"; i = 2; now, the List has the following: "Sausage" "brownie" "waffles" essentially, somwhere along the line, the list got out of order. Now, I need it to be in the original order, but it has to be the string list as opposed to me trying to access the properties of each individual object in the original list. is there a way to say "sort List to match List's properties with the same values"? I'm thinking Linq has my answers, but I dont know for sure, and I dont know where to begin. Any suggestions would be appreciated :)
______________________ Oh Hamburgers!
You can write a custom comparer for the object to be used in the list? I don't really understand the problem but sometimes that is a good solution for sorting woes, There is also the SortedList class available for use.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego. -
Is it possible to sort a generic list base don the sort of another generic list? Here is what I am working with: I have a List object that I built out of a List, where the strings in the first list are populated with a specific string property from the second. so, say this is my example, the List<Q_object> object is made up of this: lets say Q_object has the follwing properties: string str1 string str2 int i and my objects in the list are specifically: Q_object[0] has str1 = "fudge"; str2 = "brownie"; i = 0; Q_object[1] has str1 = "Beer"; str2 = "Sausage"; i = 1; Q_object[2] has str1 = "Pancakes"; str2 = "waffles"; i = 2; now, the List has the following: "Sausage" "brownie" "waffles" essentially, somwhere along the line, the list got out of order. Now, I need it to be in the original order, but it has to be the string list as opposed to me trying to access the properties of each individual object in the original list. is there a way to say "sort List to match List's properties with the same values"? I'm thinking Linq has my answers, but I dont know for sure, and I dont know where to begin. Any suggestions would be appreciated :)
______________________ Oh Hamburgers!
What is the reason that you need to sort the list of strings? If it should just be a copy of some of the data in the list of objects, can't you just recreate the list? Do you actually have to create the list of strings, can't you just read the data from the list of objects?
Despite everything, the person most likely to be fooling you next is yourself.
-
What is the reason that you need to sort the list of strings? If it should just be a copy of some of the data in the list of objects, can't you just recreate the list? Do you actually have to create the list of strings, can't you just read the data from the list of objects?
Despite everything, the person most likely to be fooling you next is yourself.
the logic being used is very flexible and was designed to grab strings from any properties contained in a list of any objects. if you know the properties of the object (and you should at least one, otherwise you shouldn't be using it ;))and return the valu eof that property in each instance of the object in the list. Its hard to read, I know, but it works. the issue is that somewhere along the line, the data is getting out of sort, and I dont have time (yet) to add logic for sorting into the method. (it would have to identify the other property in the object to sort from, if such a property exists, blah blah blah) Why wouldnt i just access the property of each individual object in the list? Believe it or not, this was written to run through huge XML strings and grab the potential instances of object descriptions contained within, and then return the property values, if the objects exist, and if their properties arent null. I didnt design it, but I have to use it, so this method ignores the "what if" and just returns what is. And now i have to work with what comes out th eother side.
______________________ Oh Hamburgers!
-
the logic being used is very flexible and was designed to grab strings from any properties contained in a list of any objects. if you know the properties of the object (and you should at least one, otherwise you shouldn't be using it ;))and return the valu eof that property in each instance of the object in the list. Its hard to read, I know, but it works. the issue is that somewhere along the line, the data is getting out of sort, and I dont have time (yet) to add logic for sorting into the method. (it would have to identify the other property in the object to sort from, if such a property exists, blah blah blah) Why wouldnt i just access the property of each individual object in the list? Believe it or not, this was written to run through huge XML strings and grab the potential instances of object descriptions contained within, and then return the property values, if the objects exist, and if their properties arent null. I didnt design it, but I have to use it, so this method ignores the "what if" and just returns what is. And now i have to work with what comes out th eother side.
______________________ Oh Hamburgers!