Skip to main content
 首页 » 编程设计

c#之困难的设置和获取组合属性

2024年02月13日13wayfarer

我会结合 FirstName 和 LastName 两个属性和 FullName 属性来创建 但是他们不知道在集合中写什么。

 public class Customer : CommonEntity 
{ 
 
 
    public String FirstName 
    { 
        get; 
        set; 
    } 
 
    public String LastName 
    { 
        get; 
        set; 
    } 
 
 
 
    public string FullName 
    { 
        get { return this.FirstName + " " + this.LastName; } 
        set { **.....** } 
 
    } 
 
 
} 

谢谢

请您参考如下方法:

从全名中推导出名字和姓氏非常困难。想想“John Charles Lee”、“Pedro de la Cruz”、“Pieter van den Hoogenband”等。

如果您使用序列化,请不要序列化 ​​FullName 属性。大多数序列化程序不会对 get 属性做任何事情。