递归一个List<T>,可自己根据需要改造为通用型。
递归方法
1 public class ProvinceOrg : ICloneable 2 { 3 public int orgId { get; set; } 4 public int parentOrgId { get; set; } 5 public int areaId { get; set; } 6 public string areaCode { get; set; } 7 public string orgName { get; set; } 8 public string fullOrgName { get; set; } 9 public List<ProvinceOrg> children { get; set; } 10 11 /// <summary> 12 /// 克隆并返回一个对象。 13 /// </summary> 14 /// <returns></returns> 15 public ProvinceOrg Clone() 16 { 17 ProvinceOrg p = (ProvinceOrg)this.MemberwiseClone(); 18 p.children = new List<ProvinceOrg>(); 19 return p; 20 } 21 22 object ICloneable.Clone() 23 { 24 return this.Clone(); 25 } 26 }
实体类
1 public class ProvinceOrg : ICloneable 2 { 3 public int orgId { get; set; } 4 public int parentOrgId { get; set; } 5 public int areaId { get; set; } 6 public string areaCode { get; set; } 7 public string orgName { get; set; } 8 public string fullOrgName { get; set; } 9 public List<ProvinceOrg> children { get; set; } 10 11 /// <summary> 12 /// 克隆并返回一个对象。 13 /// </summary> 14 /// <returns></returns> 15 public ProvinceOrg Clone() 16 { 17 ProvinceOrg p = (ProvinceOrg)this.MemberwiseClone(); 18 p.children = new List<ProvinceOrg>(); 19 return p; 20 } 21 22 object ICloneable.Clone() 23 { 24 return this.Clone(); 25 } 26 }
欢迎评论留言交流