Click here to Skip to main content
16,007,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: Allocating a pointer Pin
Eslam Afifi5-Oct-08 18:56
Eslam Afifi5-Oct-08 18:56 
AnswerRe: Allocating a pointer Pin
Guffa5-Oct-08 21:19
Guffa5-Oct-08 21:19 
AnswerRe: Allocating a pointer Pin
hockymot2008_20096-Oct-08 3:14
hockymot2008_20096-Oct-08 3:14 
QuestionRijndael Managed Pin
kenexcelon5-Oct-08 14:19
kenexcelon5-Oct-08 14:19 
AnswerRe: Rijndael Managed Pin
Cyrilix5-Oct-08 19:01
Cyrilix5-Oct-08 19:01 
AnswerRe: Rijndael Managed Pin
Pedram Behroozi5-Oct-08 21:20
Pedram Behroozi5-Oct-08 21:20 
QuestionI Don't Understand How To Sort A Generic List of Objects [modified] Pin
That Asian Guy5-Oct-08 11:21
That Asian Guy5-Oct-08 11:21 
AnswerRe: I Don't Understand How To Sort A Generic List of Objects Pin
User 66585-Oct-08 11:34
User 66585-Oct-08 11:34 
You need to provide your own comparison method for your product class which lets you compare two products in the way you want to. Here's an example:

private static int CompareProducts(Product x, Product y)
{
        if (x == null)
        {
            if (y == null)
            {
                // If x is null and y is null, they're equal. 
                return 0;
            }
            else
            {
                // If x is null and y is not null, y is greater. 
                return -1;
            }
        }
        else
        {
            // If x is not null...
            if (y == null) // ...and y is null, x is greater.
            {
                return 1;
            }
            else
            {
                // ...and y is not null, compare by whatever you want :-)
                // here we compare either by name if different, otherwise by quantity in stock
                if(x.Name == y.Name)
                    return x.QuantityInStock.CompareTo(y.QuantityInStock);
                else
                    return x.Name.CompareTo(y.Name);
            }
        }

}


and then sort them:

producs.Sort(CompareProducts);


regards

modified 12-Sep-18 21:01pm.

QuestionRe: I Don't Understand How To Sort A Generic List of Objects Pin
That Asian Guy5-Oct-08 12:10
That Asian Guy5-Oct-08 12:10 
AnswerRe: I Don't Understand How To Sort A Generic List of Objects Pin
User 66585-Oct-08 19:21
User 66585-Oct-08 19:21 
AnswerRe: I Don't Understand How To Sort A Generic List of Objects Pin
#realJSOP5-Oct-08 12:12
professional#realJSOP5-Oct-08 12:12 
AnswerRe: I Don't Understand How To Sort A Generic List of Objects Pin
Guffa5-Oct-08 14:21
Guffa5-Oct-08 14:21 
GeneralRe: I Don't Understand How To Sort A Generic List of Objects Pin
#realJSOP5-Oct-08 23:59
professional#realJSOP5-Oct-08 23:59 
GeneralRe: I Don't Understand How To Sort A Generic List of Objects Pin
leppie6-Oct-08 0:04
leppie6-Oct-08 0:04 
GeneralRe: I Don't Understand How To Sort A Generic List of Objects Pin
Guffa6-Oct-08 1:03
Guffa6-Oct-08 1:03 
GeneralRe: I Don't Understand How To Sort A Generic List of Objects Pin
#realJSOP6-Oct-08 2:48
professional#realJSOP6-Oct-08 2:48 
Questiondifference between ..... and some help Pin
E_Gold5-Oct-08 11:08
E_Gold5-Oct-08 11:08 
AnswerRe: difference between ..... and some help Pin
Thomas Stockwell5-Oct-08 11:45
professionalThomas Stockwell5-Oct-08 11:45 
GeneralRe: difference between ..... and some help Pin
User 66585-Oct-08 12:02
User 66585-Oct-08 12:02 
AnswerRe: difference between ..... and some help Pin
Pedram Behroozi5-Oct-08 21:42
Pedram Behroozi5-Oct-08 21:42 
AnswerRe: difference between ..... and some help Pin
Harvey Saayman5-Oct-08 22:51
Harvey Saayman5-Oct-08 22:51 
Answerdifference between == and Equals [modified] Pin
DaveyM696-Oct-08 0:36
professionalDaveyM696-Oct-08 0:36 
QuestionDifferent references for Release and Debug Pin
Green Fuze5-Oct-08 10:57
Green Fuze5-Oct-08 10:57 
AnswerRe: Different references for Release and Debug Pin
Thomas Stockwell5-Oct-08 11:46
professionalThomas Stockwell5-Oct-08 11:46 
GeneralRe: Different references for Release and Debug Pin
Green Fuze5-Oct-08 11:54
Green Fuze5-Oct-08 11:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.