如果没有在C#中定义,那么构造函数的访问修饰符是什么? [英] What will be the access modifier of the constructor if that is not defined in C#?

查看:363
本文介绍了如果没有在C#中定义,那么构造函数的访问修饰符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下c#类中定义的构造函数的访问修饰符是什么?



类SampClass 
{
int var1;
int var2;

SampClass( int var1, int var2)
{
this .var1 = var1;
this .var2 = var2;
}
}

解决方案

构造函数的访问说明符是私有的(默认情况下)。



注意:如果没有显式定义构造函数,将自动定义公共默认构造函数。


如果我们不这样做为任何方法或构造函数指定访问修饰符,然后默认为私有。



和任何类,如果我们不指定访问修饰符,则默认为内部。


参数化构造函数。

For Detail Go with this link

C#中的构造函数介绍 [ ^ ]



http://www.programcall.com/16/ csnet / constructor-types-with-example-programs-in-csnet.aspx [ ^ ]



谢谢,

What will be the access modifier of the constructor defined in the following c# class?

Class SampClass
{
   int var1;
   int var2;
   
   SampClass(int var1,int var2)
   {
      this.var1=var1;
      this.var2=var2;
   }
}

解决方案

The access specifier of constructor is private(by default).

Note: if no constructor is explicitly defined, a public default constructor will be automatically defined.


If we don't specify access modifier for any method or constructor then it is Private by default.

and for any class if we don't specify access modifier then it is Internal by default.


Parameterized Constructor.
For Detail Go with this link
An Intro to Constructors in C#[^]
or
http://www.programcall.com/16/csnet/constructor-types-with-example-programs-in-csnet.aspx[^]

Thanks,


这篇关于如果没有在C#中定义,那么构造函数的访问修饰符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆