分享

VA15.4 索引器概述及声明

 时间剧毒 2019-04-29

using System;

using System.Collections.Generic;

using System.Text;

namespace VA15.__索引器概述及声明

{

    class Program

    {

        public class Clerk {

            private string name;   //内部使用

            public string Name {   //属性 外部引用

                get { return name ;}

                set { name = value; } 

            }

            private string gender;

            public string Gender {

                get { 

                      if (gender !="男" && gender !="女" ) gender ="男";

                      return gender;

                }

                set { gender = value; }

            }

            //数组索引器

            private int[] myint=new int [10];

            //public int this[int index] {

            //    get { return myint[index]; }

            //    set { myint[index] = value; }

            //}

            //虚拟索引器 virtual

            //public  virtual  int this[int index]

            //{

            //    get { return myint[index]; }

            //    set { myint[index] = value; }

            //}

            //外部索引器 因为外部索引器不提供任何实际的实现,所有它的每个访问器声明 都由一个分号组成

            //public extern int this[int index]

            //{

            //    get;

            //    set;

            //}

             //抽象索引器 当要定义为抽象的索引 必须提供空的 get set  用来继承

        }

        //抽象索引器

        abstract class indexEaxmple { 

            public abstract int this[int index]

            {

                get;

                set;

            }

        }

        static void Main(string[] args)

        {

        }

    }

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多