如何连接一个属性中的字段

Moi*_*oiz 2 c# linq asp.net

我有物业清单.喜欢

public string name {get;set;}
public string lastname {get;set;}
public string age {get;set;}
public string fullName {get;set;}
Run Code Online (Sandbox Code Playgroud)

现在我要做的是连接最后一个属性中的前3个'FullName'属性.

意味着我有 name = John, Lastname = smith, age = 20

然后

Fullname should be John Smith 20
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点.我应该Domain Class在帮助下setter property做到这一点,还是可以使用Linq.

我带来了1000多条记录IEnumerable .我怎样才能做到这一点.我想避免循环记录.

Jon*_*eet 9

我会将它设为只读属性 - 除非你想在设置时开始将值解析为位.所以:

public string FullName
{
    // This is assuming you've also fixed the property names to be conventional
    // I'd also suggest changing "Name" to "GivenName" or "FirstName".
    get { return string.Format("{0} {1} {2}", Name, LastName, Age); }
}
Run Code Online (Sandbox Code Playgroud)

如果你真的想要一个setter,我会建议用空格分割输入,然后设置其他三个属性.没有FullName属性(独立字段)单独存储,否则数据可能变得不一致.