c#基础
时间:2011-02-25 来源:LeeCe
函数重载
public abstract class Shape
{
public abstract double Area
{ get; }
}
public class Squre : Shape
{
public override double Area
{ get{ return mySide * mySide;}}
}
索引器, 模板
class SampleCollection<T>
{
// Declare an array to store the data elements.
private T[] arr = new T[100];
// Define the indexer, which will allow client code
// to use [] notation on the class instance itself.
// (See line 2 of code in Main below.)
public T this[int i]
{
get
{
// This indexer is very simple, and just returns or sets
// the corresponding element from the internal array.
return arr[i];
}
set
{
arr[i] = value;
}
}
}
// This class shows how client code uses the indexer.
class Program
{
static void Main(string[] args)
{
// Declare an instance of the SampleCollection type.
SampleCollection<string> stringCollection = new SampleCollection<string>();
// Use [] notation on the type.
stringCollection[0] = "Hello, World";
System.Console.WriteLine(stringCollection[0]);
}
}
内容都是由变量存的, 任何行为都要定义存取。
<T>模板.
public T this[int i]: 下标 返回 string, get{}set{}
相关阅读 更多 +