example 2.cs

来自「北大青鸟内部资料」· CS 代码 · 共 47 行

CS
47
字号
using System;
class VCDIndexer
{
	private int [] vcdCollection = new int[10];
	public int this[int index]
	{
		get
		{
			if (index < 0 || index >=10)
				return 0;
			else
				return vcdCollection[index];
		}
		set
		{
			if (!(index < 0 || index >= 10))
				vcdCollection[index] = value;
		}
	}
}
namespace Example_2
{
	/// <summary>
	/// 此程序演示索引器的用法
	/// </summary>
	class Class1
	{
		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			//
			VCDIndexer objVCD = new VCDIndexer();
			objVCD[1]=125;
			objVCD[2]=250;
			objVCD[3]=400;
			for(int intA = 0;intA <= 3;intA++)
			{
				Console.WriteLine("VCD Collection #{0} = {1}", intA, objVCD[intA]);
			}
			//
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?