SHARE
TWEET

Linq - Ordenar pesquisar passando string

sangueroots Oct 19th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Animal
  2. {
  3.     public string nome {get; set;}
  4. }
  5.  
  6. public class Product
  7. {
  8.     public int id {get; set;}
  9.     public string name {get; set;}
  10.    
  11.     public Product(int _id, string _name)
  12.     {
  13.         id = _id;
  14.         name = _name;
  15.     }
  16. }
  17.  
  18. private static ObservableCollection<Product> products = new ObservableCollection<Product>
  19.  
  20.     {
  21.  
  22.         new Product(1, "Book"),
  23.         new Product(2, "Desktop Computer"),
  24.         new Product(3, "Notebook"),
  25.         new Product(4, "Netbook"),
  26.         new Product(5, "Business Software"),
  27.         new Product(6, "Antivirus Software"),
  28.         new Product(7, "Game Console"),
  29.         new Product(8, "Handheld Game Console"),
  30.         new Product(9, "Mobile Phone"),
  31.         new Product(10, "Multimedia Software"),
  32.         new Product(11, "PC Game")            
  33.     };
  34.  
  35. void Main()
  36. {
  37.     IEnumerable<Product> orderByName = products.OrderBy(x => typeof(Product).GetProperty("name").GetValue(x, null));
  38.     Console.WriteLine(orderByName);
  39. }
  40.  
  41. // Define other methods and classes here
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top