首页 > 其他 > 详细

18._6索引器在接口中的使用

时间:2016-07-13 13:44:42      阅读:269      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _18._6索引器在接口中的使用
{
    public interface ItextIndex
    {
        int this[int index]
        {
            get;
            set;
        }
    }

    class itextIndex : ItextIndex
    {
        private int[] arr = new int[10];
        public int this[int index]
        {
            get
            {
                if (index < 0 || index >= 10) return 0;
                else return arr[index];
            }
            set { if (index >= 0 && index < 10) arr[index] = value; }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            itextIndex arr = new itextIndex();
            arr[-1] = 2;
            arr[4] = 30;
            arr[9] = 34;
            arr[14] = 23;

            for(int i = -1; i < 15; i = i + 5)
            {
                Console.WriteLine("arr[{0}]:{1}", i,arr[i]);
            }
            Console.Read();
        }
    }
}

 

18._6索引器在接口中的使用

原文:http://www.cnblogs.com/zqyo2000z/p/5666438.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!