C#构造函数怎么初始化

2025-04-18 06:46:27

1、给你写个简单的构造函数class B{ private String a; private String x; public B(String a,String x) { this.a = a ; this.x = x ; } }

2、class A{ B b = new B("hello","world") ;}你要明白定义构造函数的意义,这样构造函数得意义就是给类属性定义了。

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢