C#编程-96:索引器的使用_彭世瑜_新浪博客
彭世瑜 发布时间:2017-08-05 20:39:43 ,浏览量:1
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- namespace IndexTest
- {
- class Clerk
- {
- private string name;
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- private char gender;
- public char Gender
- {
- get
- {
- return gender;
- }
- set {
- if (value != '男' && value != '女')
- gender = '男';
- else
- gender = value;
- }
- }
- private int[] myint = new int[10];
- //定义索引器
- public int this[int index]
- {
- get { return myint[index]; }
- set { myint[index] = value; }
- }
- //虚索引器
- //public virtual int this[int index]
- //{
- // get { return myint[index]; }
- // set { myint[index] = value; }
- //}
- 外部索引器
- //public extern int this[int index]
- //{
- // get;
- // set;
- //}
- }
-
- //抽象索引器
- abstract class ClerkOther
- {
- public abstract int this[int index]
- {
- set;
- get;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- }
- }
- }
1665367115
查看更多评论