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.

  • 相关阅读:
    java lambda
    ssh配置基础
    信息安全课程笔记1
    字体标记与文字布局
    字符串:格式化
    字符串
    标签详细描述
    HTML中的标签列表
    html(1)
    python列表命令
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1739939.html
Copyright © 2011-2022 走看看