C#之索引器

一、索引器:如同使用与处理”数组“一样来处理对象

二、数组”索引器“结构

private Int[] _intArray=new _int[10]
​
public int this[int index]
​
{
    Set{
        if(index>=10&&index<10)
        {
            _intArray[index]=value;
        }
    }
    Get{
        if(index<0||index>=10)
        {
            return 0;
        }
        eles
        {
            return _intArray[index];
        }
    }
}

三、索引器与数组的区别

1)索引器的索引值类型不限为整数

2)索引器允许重载

3)索引器具有Get与Set访问器

四、索引器与属性的区别

1)索引器以函数签名this来标识,而属性采用名称来标识

2)所以其可以重载,属性不能

3)索引器不能static,而属性可以

猜你喜欢

转载自blog.csdn.net/weixin_49251429/article/details/123141592