Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
GeneralRe: Allocating a pointer Pin
Guffa5-Oct-08 21:24
Guffa5-Oct-08 21:24 
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 
Just for testing I found this random class in an example file.

public class Product
    {
        public Product(string name, int quantityInStock)
        {
            _name = name;
            _quantityInStock = quantityInStock;
        }
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        private int _quantityInStock;
        public int QuantityInStock
        {
            get { return _quantityInStock; }
            set { _quantityInStock = value; }
        }
    }


Now, I created a list.

List<Product> products = new List<Product>();


And added some objects.

products.Add(new Product("A", 5));
            products.Add(new Product("B", 4));
            products.Add(new Product("C", 3));
            products.Add(new Product("D", 2));
            products.Add(new Product("E", 1));


However, when I tried using products.Sort(), I got an error. This did not surprise me since I didn't expect it to sort properly. However, I saw the other two overloads List<products>.Sort(Comparison<Product> comparison) and List<products>.Sort(IComparer<Product> comparer). I read the MSDN pages but still don't understand how to use these. Can someone provide some help?

Thanks in advance.

P.S. The casing is messed up in the post but don't worry about it Laugh | :laugh:

modified on Sunday, October 5, 2008 5:27 PM

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 
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
mve#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
mve#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
mve#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 

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.