Hi everybody,
i'm new to this forum and also to C#.
I hope someone with more experience can help me with my problem.
Given is the following Class - public class movie
-
{
-
public long ID { get; set; }
-
public string NAME { get; set; } // 0
-
public string SIZE { get; set; } // 1
-
public string TYPE { get; set; } // 2
-
public DateTime CHANGEDATE { get; set; } // 3
-
public DateTime CREATIONDATE { get; set; } // 4
-
public DateTime LASTUSED { get; set; } // 5
-
public string ARCHIVE { get; set; }
-
public string PATH { get; set; }
-
-
public movie() { }
-
}
I have an Array of movie Objects, now i wanted to sort the Array by "ARCHIVE" which contains a string like "HDD 1" or "DVD - 145".
The sorting is quite good with this line of code: - Array.Sort(MovieArray, (x, y) => string.Compare(x.ARCHIVE, y.ARCHIVE, true));
But the Problem is that when all Movies have the same ARCHIVE-String (because they are all on the same Medium) the Names of the Movies will be totaly unsorted after sorting by ARCHIVE.
It looks like this: - Before sorting:
-
["Movie A", "HDD1"]
-
["Movie B", "HDD1"]
-
["Movie C", "HDD1"]
-
["Movie D", "HDD1"]
-
["Movie E", "HDD1"]
-
- After Sorting:
-
["Movie D", "HDD1"]
-
["Movie E", "HDD1"]
-
["Movie A", "HDD1"]
-
["Movie B", "HDD1"]
-
["Movie C", "HDD1"]
-
Does anyone have a hint how to sort first by ARCHIVE and after that by NAME?
What i generally want is: -
["Movie A", "HDD1"]
-
["Movie B", "HDD1"]
-
["Movie C", "HDD1"]
-
["Movie D", "HDD1"]
-
["Movie E", "HDD1"]
-
["Movie A", "HDD2"]
-
["Movie B", "HDD2"]
-
["Movie C", "HDD2"]
-
["Movie D", "HDD2"]
-
["Movie E", "HDD2"]
-
["Movie A", "HDD4"]
-
["Movie B", "HDD4"]
-
["Movie C", "HDD4"]
-
["Movie D", "HDD4"]
-
["Movie E", "HDD4"]
-
Thank you for reading my Post and hopefully you can help me with this.
greetings regalis
Hy,
if you're able to use LINQ, you can do it that way: - //MovieArray has type movie[]
-
movie[] ordered1 = MovieArray.OrderBy(mov => mov.ARCHIVE).ThenBy(mov => mov.NAME).ToArray();
just the same, only in other notation: - movie[] ordered2 = (from mov in MovieArray
-
orderby mov.ARCHIVE, mov.NAME
-
select mov).ToArray();
2 2104
Hy,
if you're able to use LINQ, you can do it that way: - //MovieArray has type movie[]
-
movie[] ordered1 = MovieArray.OrderBy(mov => mov.ARCHIVE).ThenBy(mov => mov.NAME).ToArray();
just the same, only in other notation: - movie[] ordered2 = (from mov in MovieArray
-
orderby mov.ARCHIVE, mov.NAME
-
select mov).ToArray();
Hi ChBinder,
thank you very much for your help.
I like the way you have done the sorting and it works perfect!
100000 hugs to you :)
greetz regalis
Sign in to post your reply or Sign up for a free account.
Similar topics
by: its me |
last post by:
Let's say I have a class of people...
Public Class People
Public Sex as String
Public Age as int
Public Name as string
end class
And I declare an array of this class...
|
by: Elijah Bailey |
last post by:
I want to sort a set of records using STL's sort() function,
but dont see an easy way to do it.
I have a
char *data;
which has size mn bytes where m is size of the record and
n is the...
|
by: laniik |
last post by:
Hi. I have a problem using STL's built in sort that seems impossible
to get around.
if i have:
--------------------------------
struct object
{
int val;
}
|
by: PCHOME |
last post by:
Hi!
I have questions about qsort( ). Is anyone be willing to help?
I use the following struct:
struct Struct_A{
double value;
...
} *AA, **pAA;
|
by: Daniel |
last post by:
does C# have any collection objects that support sort functionality so that
I dont have to write my own sorting algorithm?
|
by: yeti349 |
last post by:
Hi, I'm using the following code to retrieve data from an xml file and
populate a javascript array. The data is then displayed in html table
form. I would like to then be able to sort by each...
|
by: Alex Chudnovsky |
last post by:
I have come across with what appears to be a significant performance bug in
..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same
data. Same data on the same CPU gets sorted a...
|
by: fdu.xiaojf |
last post by:
Hi,
It seems that an array acts like an list very much, except it doesn't
have a method sort.
Regards,
|
by: John Devlon |
last post by:
Hi,
I've created my own class containing a few properties like name, zip-code
and savings.
At some point i'm storing several objects in an array.
Does anyone know how to sort the array using...
|
by: JosAH |
last post by:
Greetings,
I was asked to write a Tip Of the Week; so here goes: a lot of topics are
started here in this forum (and a lot of other forums too) mentioning a
problem about sorting data.
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |