我想在 C# 中有一个索引属性:
public Boolean IsSelected[Guid personGuid]
{
get {
Person person = GetPersonByGuid(personGuid);
return person.IsSelected;
}
set {
Person person = GetPersonByGuid(personGuid);
person.IsSelected = value;
}
}
public Boolean IsApproved[Guid personGuid]
{
get {
Person person = GetPersonByGuid(personGuid);
return person.IsApproved;
}
set {
Person person = GetPersonByGuid(personGuid);
person.IsApproved= value;
}
}
Visual Studio 抱怨非整数索引器语法:
我知道.NET 支持非整数索引器。
用另一种语言我会写:
private
function GetIsSelected(ApproverGUID: TGUID): Boolean;
procedure SetIsSelected(ApproverGUID: TGUID; Value: Boolean);
function GetIsApproved(ApproverGUID: TGUID): Boolean;
procedure SetIsApproved(ApproverGUID: TGUID; Value: Boolean);
public
property IsSelected[ApproverGuid: TGUID]:Boolean read GetIsSelected write SetIsSelected;
property IsApproved[ApproverGuid: TGUID]:Boolean read GetIsApproved write SetIsApproved;
end;