{
    private int id;
    
private string prodName;
    
private decimal price;

    
public static Comparison<Product> PriceComparison = delegate(Product p1, Product p2)
                                                        {
                                                            
return p1.price.CompareTo(p2.price);
                                                        };

    
public static Comparison<Product> IDComparison = delegate(Product p1, Product p2)
                                                     {
                                                         
return p1.id.CompareTo(p2.id);
                                                     };

    
public int ProductID
    {
        
get { return id; }
        
set { id = value; }
    }

    
public string ProductName
    {
        
get { return prodName; }
        
set { prodName = value; }
    }

    
public decimal UnitPrice
    {
        
get { return price; }
        
set { price = value; }
    }

    
public Product(int id, string prodName, decimal price)
    {
        
this.id = id;
        
this.prodName = prodName;
        
this.price = price;
    }

    
#region IComparable<Product> Members

    
public int CompareTo(Product other)
    {
        
return ProductName.CompareTo(other.ProductName);
    }

    
#endregion

    
public override string ToString()
    {
        
return string.Format("Id: {0} Name: {1} Price: {2}", id, prodName, price);
    }
}


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

products.Sort(
delegate(Product p1, Product p2)
              {
                  
return p1.ProductName.CompareTo(p2.ProductName);
              });

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-05-14
  • 2021-05-24
  • 2022-01-28
  • 2021-11-17
  • 2021-05-17
猜你喜欢
  • 2022-02-20
  • 2021-12-11
  • 2021-10-27
相关资源
相似解决方案