C# 好像不支持。你可以这样写:
struct student
{
private string name;
private uint age;
public string Sname
{
get
{
return name;
}
set
{
name = value;
} }
public uint Sage
{
get
{
return age; }
set
{
if (value < 0 || value > 150)
{
throw new ArgumentException("age erro");
}
age = value;
}
}
}
class ourClass
{
student[] s;
public ourClass(int capcity)
{
s = new student[capcity];
}
public student this[int index]
{
get
{
if (index < 0 || index >= s.Length)
throw new ArgumentException("溢出");
return s[index];
}
set
{
if (index < 0 || index >= s.Length)
throw new ArgumentException("溢出");
s[index] = value;
}
}
}
struct student
{
private string name;
private uint age;
public string Sname
{
get
{
return name;
}
set
{
name = value;
} }
public uint Sage
{
get
{
return age; }
set
{
if (value < 0 || value > 150)
{
throw new ArgumentException("age erro");
}
age = value;
}
}
}
class ourClass
{
student[] s;
public ourClass(int capcity)
{
s = new student[capcity];
}
public student this[int index]
{
get
{
if (index < 0 || index >= s.Length)
throw new ArgumentException("溢出");
return s[index];
}
set
{
if (index < 0 || index >= s.Length)
throw new ArgumentException("溢出");
s[index] = value;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货