Guest User

Untitled

a guest
Aug 14th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public class Employee
  2. {
  3. public int Id { get; set; }
  4. public string Name { get; set; }
  5. }
  6.  
  7. IList<Employee> EmpList ;
  8.  
  9. Or
  10.  
  11. List<Employee> EmpList ;
  12.  
  13. IList<Employee> EmpList = new List<Employee>();
  14.  
  15. List<Employee> EmpList = new List<Employee>();
  16.  
  17. var EmpList = new List<Employee>(); // EmpList is List<Employee>
  18.  
  19. IList<Employee> EmpList = new IList<Employee>();
  20.  
  21. public void IterateEmployees(IEnumerable<Employee> employees)
  22. {
  23. foreach(var employee in employees)
  24. {
  25. // ...
  26. }
  27. }
  28.  
  29. //this will not compile
  30. IList<Employee> EmpList = new IList<Employee>();
  31.  
  32. //this is what you're really looking for:
  33. List<Employee> EmpList = new List<Employee>();
  34.  
  35. //but this will also compile:
  36. IList<Employee> EmpList = new List<Employee>();
  37.  
  38. [SerializableAttribute]
  39. public class List<T> : IList<T>, ICollection<T>,
  40. IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>,
  41. IEnumerable
Add Comment
Please, Sign In to add comment