日期:2014-05-18  浏览次数:20811 次

新人求问 c#中this的用法
看书时书上习题答案的代码
 public class ShortCollection<T>:IList<T>
  {
  protected Collection<T> innerCollection;
  protected int maxSize = 10;
  public ShortCollection()
  : this(10)  
  {
  }
  public ShortCollection(int size)
  {
  maxSize = size;
  innerCollection = new Collection<T>();
  }
  public ShortCollection(List<T> list)
  : this(10, list)  
  {
  }
那两个this时怎么个意思???
  public T this[int index]  
  {
  get
  {
  return (innerCollection as IList<T>)[index];
  }
  set
  {
  (innerCollection as IList<T>)[index] = value;
  }
  }
还有这个
实在理解不能 求指导

------解决方案--------------------
MSDN帮助(this 关键字):
http://msdn.microsoft.com/zh-cn/library/dk1507sz.aspx
------解决方案--------------------
呵呵,this就是自己,this instance
因为在class中写的method是作为instance的template
所以instance会在runtime动态持有method
比如说,
C# code
class SampleClass {
  public void SampleMethod(){...}
}