摘要:
class IndexerExample
{
public Hashtable list = new Hashtable();
public int this[string name]
{
get { return (int) list[name]; }
set { list[name] = value; }
}
}
//class IndexerExample
//{
// public string[] stringList = new string[10];
// public string this[int index]
// {
// get { return stringList[index]; }
// set { stringList[index] = value.ToString(); }
// }
//} 阅读全文
摘要:
public class Student
{
public string name;
public int id;
public int age=22;
//set中的判断
public int Id
{
get { return id; }
set {
if (value id = value;
else
id = 100;
}
}
//get后的计算
public string Name
{
get { return "Hello "+name; }
set { name = value; }
}
阅读全文