什么是c#中构造函数和类的默认访问修饰符? [英] what is default access modifier for constructor and class in c#?

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

问题描述

某处它写的是私有的,而且它在内部,所以我有点困惑。

somewhere it written private and somewhere its internal,so i am bit confused.

推荐答案

你最好参考 C#语言规范 [ ^ ]

根据具有内部访问权限的类修改,构造函数将privet访问权限修改为默认值。检查 C#中的默认访问修饰符是什么? [< a href =http://stackoverflow.com/questions/2521459/what-are-the-default-access-modifiers-in-ctarget =_ blanktitle =New Window> ^ ]更多信息
You better refer C# Language Specification[^]
as per that class having internal access modified and constructor having privet access modified as default. check What are the Default Access Modifiers in C#?[^] for more information


对于类默认访问修饰符

1. 内部如果声明了类直接在命名空间内

2. 私人如果它是嵌套类

更多请看这里:http://msdn.microsoft.com/en-us/library/ms173121.aspx [ ^ ]



对于构造函数默认访问修饰符是:

private 如果程序员定义它但如果程序员没有明确定义构造函数,则公共默认构造函数将自动定义)

欲了解更多信息,请查看: http://stackoverflow.com/questions/2521459/what-are-the-default-access-modifiers-in-c [ ^ ]



谢谢。
For a class default access modifier :is
1. Internal if class declared directly within a namespace
2. private if it is a nested class
For more have a look here: http://msdn.microsoft.com/en-us/library/ms173121.aspx[^]

For constructor default access modifier is:
private if programmer defines it but if no constructor is explicitly defined by programmer, a public default constructor will be automatically defined)
For more have a look at: http://stackoverflow.com/questions/2521459/what-are-the-default-access-modifiers-in-c[^]

Thanks.


默认为public。但是,您可以根据自己的要求进行更改。
It is by default public. However you can change it as per your requirement.


这篇关于什么是c#中构造函数和类的默认访问修饰符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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