Hi I have a generic list populated by a structure and sorts the contents of
the list based on the day and project # that is part of the structure. I
would like to modify it to also sort on the start time as the third sort
parameter? thanks.
public class Comparer : IComparer<merge outstruct>
{
public int Compare(mergeou tstruct a, mergeoutstruct b)
{
int result = DateTime.Compar e(a.day, b.day);
if (result == 0)
{
result = a.projectnum.Co mpareTo(b.proje ctnum);
}
return result;
}
}
public struct mergeoutstruct
{
public Int32 projectnum;
public DateTime day;
public TimeSpan time;
public Double timeout;
public DateTime starttime;
public DateTime endtime;
}
Comparer comp = new Comparer(); //sorts by day and project #.
merglist.Sort(c omp.Compare);
--
Paul G
Software engineer. 2 4475
Paul,
You just have to add one more check, like so:
public class Comparer : IComparer<merge outstruct>
{
public int Compare(mergeou tstruct a, mergeoutstruct b)
{
int result = DateTime.Compar e(a.day, b.day);
if (result == 0)
{
result = a.projectnum.Co mpareTo(b.proje ctnum);
// New check.
if (result == 0)
{
// Compare the start time.
result = a.starttime.Com pare(b.starttim e);
}
}
return result;
}
}
You probably want to compare against the end time as well, in the event
that the start times are the same.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:B6******** *************** ***********@mic rosoft.com...
Hi I have a generic list populated by a structure and sorts the contents
of
the list based on the day and project # that is part of the structure. I
would like to modify it to also sort on the start time as the third sort
parameter? thanks.
public class Comparer : IComparer<merge outstruct>
{
public int Compare(mergeou tstruct a, mergeoutstruct b)
{
int result = DateTime.Compar e(a.day, b.day);
if (result == 0)
{
result = a.projectnum.Co mpareTo(b.proje ctnum);
}
return result;
}
}
public struct mergeoutstruct
{
public Int32 projectnum;
public DateTime day;
public TimeSpan time;
public Double timeout;
public DateTime starttime;
public DateTime endtime;
}
Comparer comp = new Comparer(); //sorts by day and project #.
merglist.Sort(c omp.Compare);
--
Paul G
Software engineer.
it works, thanks!
--
Paul G
Software engineer.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Paul,
You just have to add one more check, like so:
public class Comparer : IComparer<merge outstruct>
{
public int Compare(mergeou tstruct a, mergeoutstruct b)
{
int result = DateTime.Compar e(a.day, b.day);
if (result == 0)
{
result = a.projectnum.Co mpareTo(b.proje ctnum);
// New check.
if (result == 0)
{
// Compare the start time.
result = a.starttime.Com pare(b.starttim e);
}
}
return result;
}
}
You probably want to compare against the end time as well, in the event
that the start times are the same.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Paul" <Pa**@discussio ns.microsoft.co mwrote in message
news:B6******** *************** ***********@mic rosoft.com...
Hi I have a generic list populated by a structure and sorts the contents
of
the list based on the day and project # that is part of the structure. I
would like to modify it to also sort on the start time as the third sort
parameter? thanks.
public class Comparer : IComparer<merge outstruct>
{
public int Compare(mergeou tstruct a, mergeoutstruct b)
{
int result = DateTime.Compar e(a.day, b.day);
if (result == 0)
{
result = a.projectnum.Co mpareTo(b.proje ctnum);
}
return result;
}
}
public struct mergeoutstruct
{
public Int32 projectnum;
public DateTime day;
public TimeSpan time;
public Double timeout;
public DateTime starttime;
public DateTime endtime;
}
Comparer comp = new Comparer(); //sorts by day and project #.
merglist.Sort(c omp.Compare);
--
Paul G
Software engineer.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Leszek Klich |
last post by:
Hello All !
I have a task:
QT library:
List ListBox. I generating n random numbers from range 0 to 100. I have to
sort it by hand... It has to look nicely. It's my workhome from my school.
Sorting must visualise (preview) process in list. Any method of sorting. I
do not want to use stantard methods including to QT. I have ready: (main
window, list, slider (count elements to generic), button: generic numeric
|
by: Owen T. Soroke |
last post by:
Using VB.NET
I have a ListView with several columns.
Two columns contain integer values, while the remaining contain string
values.
I am confused as to how I would provide functionality to sort columns
based on the column header the user has clicked in both Ascending and
Descending formats.
|
by: Arthur Dent |
last post by:
How do you sort a generic collection derived from
System.Collections.ObjectModel.Collection?
Thanks in advance,
- Arthur Dent
|
by: ASP Developer |
last post by:
I have a generic list of objects. These objects have a text field that
contains a letter for the first character and numbers for the next three.
For example, "A001".
I need to sort these by letter first and then by number. What is the best
way to sort these?
Any help would be greatly appreciated.
|
by: Kittyhawk |
last post by:
I would like to sort an Arraylist of objects on multiple properties. For
instance, I have a Sort Index property and an ID property (both integers).
So, the results of my sort would look like this:
sort index, id
1000,1
1000,2
1000,3
1001,1
1001,2
| |
by: Wing Siu |
last post by:
Dear All
I would like to develop a generic class sorting function.
Currently, when I need sort a collection of user class, for example: Person,
Exhibition, Country
I need implement a comparer class for each user class, for example:
PersonComparer, ExhibitionComparer, CountryComparer
Is that any solution that allow me sort different class by using the same
|
by: kurt sune |
last post by:
I have a an aspx page with a gridview.
The gridview is data bound to a generic list of custom classes.
The gridview's DataSource is thus not set.
Now I want to add sorting to it.
So I create an eventhandler thus:
Protected Sub grdResult_Sorting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewSortEventArgs) Handles grdResult.Sorting
|
by: Harry Haller |
last post by:
Hello, I want to implement a generic list which will be used to
display 7 columns in a GridView. One should be able to sort, filter
and page each of the 7 columns. Ideally the filter should be
implemented simultaneously for multiple columns - but the data need
only be sorted by a single column at a time. Sorting should be both
ascending and descending.
I'm currently using a DataView but it's far too slow, because there
are a large...
|
by: slapsh0t11 |
last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment:
Here is my class file (Sorts.java):
import java.util.*;
/**
|
by: jrod11 |
last post by:
hi,
I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums there are, it crashes.
There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)?
Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html
Here is some jquery js that I think...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |