【发布时间】:2013-12-29 12:27:34
【问题描述】:
我在浏览一个示例 C# (WPF) 代码时遇到了以下代码块:
public string this[string columnName]
{
get
{
if (columnName == "FirstName") {
return string.IsNullOrEmpty(this.firstName) ? "Required value" : null;
}
if (columnName == "LastName") {
return string.IsNullOrEmpty(this.lastName) ? "Required value" : null;
}
return null;
}
}
此代码块用于执行数据验证。从外观上看,它看起来像一个属性,因为它包含一个 get{} 块。只想了解语法的语义含义:
public string this[string columnName]
【问题讨论】:
-
感谢您的快速回复!