【发布时间】:2011-09-23 16:00:23
【问题描述】:
如果类中的属性满足特定条件,例如/为空,我如何使该属性返回特定字符串
public class Person
{
public string Name{get;set;}
publc string MiddleName{get;set;}
public string Surname{get;set;}
public string Gender{get;set;}
}
List<Person> people = repo.GetPeople();
List<Person> formatted = people.GroupBy(x=>x.Gender).//?? format Gender to be a certain string eg/"Not Defined" if blank
【问题讨论】:
-
可能不适用,但我有一个性别枚举,因为只有这么多选项。
-
你是对的,但这只是一个例子,不是我的真实代码
标签: c# .net linq c#-4.0 .net-4.0