C#构造方法赋初始值

匿名 (未验证) 提交于 2019-12-03 00:38:01
namespace ConsoleApplication1 {     public class Test     {          public int Id { get; set; }         public string Name { get; set; }         public string Country { get; set; }          //public Test(int id, string name) : this(Id, Name, Country: "china")         //{          //}         public Test(int id, string name, string country)         {             Id = id;             Name = name;             Country = country;         }          public Test(int id, string name) : this(id, name, "默认值")         {          }          public override string ToString()         {             return this.Id + "---" + this.Name + "---" + this.Country;         }     } }

using System;  namespace ConsoleApplication1 {     static class Program     {          static void Main(string[] args)         {              Test test = new Test(1, "wang");             Console.WriteLine(test);             Test test1 = new Test(1, "wang121","lallaallaalal");             Console.WriteLine(test1);             Console.ReadKey();         }     } }

转载请标明出处:C#构造方法赋初始值
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!