using System;
namespace CompCS
{
public class StringComponent
{
private string[] StringSet;
public StringComponent()
{
StringSet = new string[]{"C# string 0","C# string 1","C#string 2","C#string 3"};
}
public string GetString(int index)
{
{
if(index>=StringSet.Length || (index<0))
throw new IndexOutOfRangeException ();
}
return stringSet[index];
}
public int count
{
get
{
return StringSet.Length;
}
}
static void Main()
{
StringComponent t=new StringComponent();
int a=t.count;
Console.WriteLine(a.ToString());
Console.ReadLine();
}
}
}
參考答案:return stringSet[index]; //这里是StringSet,注意大小写