欢迎光临散文网 会员登陆 & 注册

构造函数的参数

2023-02-13 06:44 作者:此城过客  | 我要投稿

之前的构造函数, public Customer(string arg1,string arg2,int arg3,string arg4

他的参数写arg1,arg2,这样在主程序里引用的时候,不知道是什么意思,不方便阅读。因此构造函数的参数可以这么写:

namespace ConsoleApp4

{

    class Weapon

    {

        public string name;

        public string address;

        public int age;

        public string createTime;


        public Weapon(string name, string address, int age, string createTime)

        {

            this.name = name;//this代表当前对象

            this.address = address;

            this.age = age;

            this.createTime = createTime;

        }

    }

}


构造函数的参数的评论 (共 条)

分享到微博请遵守国家法律