IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New C# sorting a list of strings
When my users chooses multiple files from a file-pick box, the order they are returned does not seems right to them. It is as if it is in reverse to what they picked, but not ALWAYS.

I'm using a foreach in FileNames to pull them, adding them to my list box. I would like to sort them before adding them so they always show up in the same order.

This FEELS like I should be using a SortedList(), but further reading looks like this is major overkill. Is there a way to return the contents of a list in sorted order with constructing this first?

If I HAVE to use it, does anyone have an example they'd like to share? It seems I always end up with a lot more code than I should.
New something like...
...net.com.java.sun.make.you.type.lots.system.exec.out.woo("perl -e print sort <insert string things here>");

?

:-)


Peter
[link|http://www.debian.org|Shill For Hire]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Blog]
New Re: C# sorting a list of strings
Try the Array.Sort() method. If your list class derives from there, you've probably already got the functionality built in.
All I want for my birthday is a new President!
New Here's what I ended up with
\n   SortedList srtHolder = new SortedList();\n   \n   foreach (string strFileName in fdlgGetFile.FileNames)\n   {\n      string short_file = Path.GetFileName(strFileName); \n      srtHolder.Add(short_file,short_file);\n   }\n\n\n   foreach (string short_file in srtHolder.Keys)\n   {\n      if (lstFiles.FindStringExact(short_file) == -1)\n      {\n         lstFiles.Items.Add(short_file);\n      }\n   }\n\n


Feels kind of evil, using the filename as both the key and the data,
but it does return in sorted order for putting it in to the list box.
New Did you look at Array.Sort() ?
Sorts the elements in an entire one-dimensional Array using the IComparable interface implemented by each element of the Array.

[C#]
[Serializable]
public static void Sort(
Array array
);
Parameters
array
The one-dimensional Array to sort.
--

... a reference to Presidente Arbusto.
-- [link|http://itre.cis.upenn.edu/~myl/languagelog/archives/001417.html|Geoffrey K. Pullum]
New I did now
Thanks.
I knew that last one felt wrong!
     C# sorting a list of strings - (broomberg) - (5)
         something like... - (pwhysall)
         Re: C# sorting a list of strings - (inthane-chan) - (3)
             Here's what I ended up with - (broomberg) - (2)
                 Did you look at Array.Sort() ? - (Arkadiy) - (1)
                     I did now - (broomberg)

You will be boiled in vegetable oil and packaged for housecats.
53 ms