首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

新人求问 c#中this的用法,该怎么处理

2012-03-08 
新人求问 c#中this的用法看书时书上习题答案的代码public class ShortCollectionT:IListT{protected C

新人求问 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(){...}} 

热点排行