不推荐List<T>做API
原因有如下两点:
1.首先List<T> 设计之初就没有设计成可扩展的,我们不能重新其任何方法。这就意味着,我们操作List<T>的时候却不

能有任何的通知机制,而Collection<T>却提供了SetItem虚方法以供重写,以便于我们在修改成员信息或者添加成员的

时候可以自定义实现通知机制。
2.其次List<T>有许多的成员在很多的使用场景下是相关联的,这就是我们所说的List<T>对外公开了过多的成员方法,

想象下,ListView中的Items属性返回(包含了众多属性的)List<T>。来看看实际上ListView.Items的返回类型;它的方

式更简单,类似于Collection<T>或ReadOnlyCollection<T>。

由于List<T>与Collection<T>的内容比较多,大家感兴趣可以自己查看下,这里只把Collection<T>的部分片段

列出来了。

public class Collection<T> : IList<T>, IList, IReadOnlyList<T>
{
protected virtual void ClearItems()

protected virtual void InsertItem(int index, T item)

protected virtual void RemoveItem(int index)

protected virtual void SetItem(int index, T item)
}
而且其公开方法大概也只有10来个,而List<T>的公开发方法粗略的估计一下至少也得有30个以上。所以明显的可以看出

来,对于系统内部使用为了方便,List<T>提供了更便利的操作,而且在性能上,存储上做了大量的优化。但是如果作为

API显然有些过于庞大和不可控了。

(原文:http://blogs.msdn.com/b/kcwalina/archive/2005/09/26/474010.aspx)

Why we don’t recommend using List<T> in public APIs的更多相关文章

  1. 不要对外公开泛型List成员

    最近在阅读Framework Design Guidelines,本着现学现用的原则,于是就用FxCop工具对代码进行规范性检查时,发现了很多问题,其中包括命名以及一些设计上的规范. 其中,Do no ...

  2. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

  3. Designing a Secure REST (Web) API without OAuth

    原文:http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/ Situation Y ...

  4. How to Write Doc Comments for the Javadoc Tool

    http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html This document describe ...

  5. Oracle Applications Multiple Organizations Access Control for Custom Code

    档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code ...

  6. 设计模式浅谈----策略模式(c#及java实现)

    一.何为策略模式 策略模式是行为型模式的一种,主要用于需要使用不同的算法来处理不同的数据对象时使用,是一种可以在运行时选择算法的设计模式.也称为政策模式. 主要解决:在有多种算法相似的情况下,使用 i ...

  7. Span<T>

    Introduction Span<T> is a new type we are adding to the platform to represent contiguous regio ...

  8. Google C++ 代码规范

    Google C++ Style Guide   Table of Contents Header Files Self-contained Headers The #define Guard For ...

  9. API Design Principles -- QT Project

    [the original link] One of Qt’s most reputed merits is its consistent, easy-to-learn, powerfulAPI. T ...

随机推荐

  1. 更改Debian Linux里面的EDT时区为CST时区

    Debian按默认安装,设置的是EDT时区.这样跟我们的系统就都对不上,因此得 改回CST. 只需要两步即可: 使用vi编辑/etc/timezone,把timezone文件的内容更改为:Asia/S ...

  2. ThinkPhp模板转Flask模板

    Template Converter 网上的PHP资源很多,项目要用Python,所以想起做一个模板转换器,从ThinkPhp转成Flask的Jinja模板. 直接指定两个目录,将目录下的模板文件转换 ...

  3. 通讯录--(适配iOS7/8/9)

    导入库#import <AddressBook/AddressBook.h> #import <AddressBookUI/AddressBookUI.h> #pragma m ...

  4. 《Machine Learning》系列学习笔记之第一周

    <Machine Learning>系列学习笔记 第一周 第一部分 Introduction The definition of machine learning (1)older, in ...

  5. web从入门开始(5)-----表单

    1.   表单的概念 是用来获取客户端用户数据的(信息)的.如:注册表单,查询表单,登录表单等. 2.  表单的工作原理 1.浏览有表单的网页,填写一些必要的信息,然后单击某个按钮,进行提交. 2.这 ...

  6. Android两种为ViewPager+Fragment添加Tab的方式

    在Android开发中ViewPager的使用是非常广泛的,而它不仅仅能够实现简单的开始引导页,还可以结合Fragment并添加Tab作为选项卡或为显示大批量页面实现强大的顺畅滑动 下面介绍两种为Vi ...

  7. Repaints and Reflows 重绘和重排版

    当浏览器下载完所有页面HTML标记,JavaScript,CSS,图片之后,它解析文件并创建两个内部数据 一棵DOM树 表示页面结构 Normal 0 7.8 磅 0 2 false false fa ...

  8. 求两个字符串的最长公共子串(LCS)

    http://tianyunpu2008.blog.163.com/blog/static/6559379920089162236915/

  9. Android中的Drawable和动画

    Android中Drawable是一种可以在Canvas上进行绘制抽象的概念,种类很多,常见的颜色和图片都可以是一个Drawable.Drawable有很多种,它们表示一种图像的概念,但是它们又不全是 ...

  10. iwebshop里面传数组且输出

    //php后台 $starttimestr = $arr[0]['forea_time']; $endtimestr = $arr[0]['end_time']; $data['starttime'] ...