zoukankan      html  css  js  c++  java
  • [Tip C# collection]List<Employee> or EmployeeList?

    List<Employee> or EmployeeList?

    In current versions of C#, to get a strongly-typed collection, you need to define a separate type for that collection. So if you want to expose a collection of employees, you created an EmployeeCollection class.

    With generics, it's now possible to just use List<Employee>, and it's also possible to write a pretty simple version of Employee collection as well:

    class EmployeeCollection: List<Employee> {}

    So, which one is preferred?

    My advice is to prefer List<Employee>, as anybody who looks at such a definition will already know what operations are present on it, while it's not clear what operations an EmployeeCollection might provide.

    I would switch to EmployeeCollection when I want to add behavior beyond what List<T> provides (I obviously *have to* switch if I want to add behavior).

    This also has the added benefit of not cluttering up the program with types that really don't need to be there.

  • 相关阅读:
    常见排序算法总结(一)
    27.移除元素
    556. 下一个更大元素 III
    503. 下一个更大元素 II
    496.下一个更大元素Ⅰ
    汇编基础
    SQL回顾
    Pandas整理
    爬取中公网新闻时政
    Python合并Excel表格
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1739939.html
Copyright © 2011-2022 走看看