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 2103
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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,...
| |