📄 indexerdemo.cs
字号:
using System;
class Titles
{
public Titles()
{
Contents = new String[25];
for (int i = 0; i < Contents.Length; i++)
Contents[i] = null;
length = 25;
}
public object this[int index]
{
set
{
if ((index >= 0) && (index < Contents.Length))
Contents[index] = value.ToString();
else
Contents[index] = null;
}
get
{
if ((index >= 0) && (index < Contents.Length))
return Contents[index];
else
return(null);
}
}
private int length;
public int Length
{
get
{
return(length);
}
}
private string [] Contents;
}
class clsIndexerDemo
{
public static void Main ()
{
Titles Books = new Titles();
Books[0] = "Rescued by C#";
Books[3] = "Jamsa's C/C++/C# Programmer's Bible";
Books[10] = "Advanced C#";
for (int i = 0; i < Books.Length; i++)
if (Books[i] != null)
Console.WriteLine(Books[i]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -