变量的默认类型。访问修饰符我的意思是。 [英] Default type of a variable. Access Modifiers I mean.

查看:121
本文介绍了变量的默认类型。访问修饰符我的意思是。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单但我无法帮助我的好奇心。有谁知道C#中变量的默认类型是什么(或更常见的是OOPS)



My Question is rather Simple but I just can't help my curiosity. Does anyone know what is the default type of a variable in C# (or more generally in OOPS)

String st = "Hello";





这个



What is the type (Access Modifiers) of this

String st 

的类型(访问修饰符)是什么。



请为您的答案提供合适的参考。我试图谷歌它,但nothig具体给出了变量的TYPE。有人说它的公众别人说是私人的。



谢谢......

here.

Please provide suitable refrences for your answer. I tried to google it but nothig is specificly given about the TYPE of a variable. Some say its public others say private.

Thanks...

推荐答案

你混淆了两个这里有不同的条款。

1)类型

2)访问修饰符



类型String st; System.String



默认访问修饰符变量/对象是私有的。
You are mixing up two different terms here.
1) Type
2) Access Modifier

Type of "String st;" is System.String.

Default access modifier of variable/object is private.


public& private不是一种变量..

它指定成员变量的访问级别的关键字。 看到这个



你的答案是(访问)成员变量的级别):私人



试试这个例子......

public & private is not a type of variable..
it keywords to specify access levels for member variables. See This

And Your Answer is (access levels for member variables): Private

Let test this example...
class Test
    {
        String Test1;
        public string Test2;
        protected string Test3;
        private string Test4;
    }

    class TestAccessLavel
    {
        static void Main()
        {
            Test e = new Test();
            // e.Test1 Not acessable
            String Test2 = e.Test2;
            //e.Test3 Not acessable
            //e.Test4 Not acessable
        }
    }





创建一个类测试并创建变量(见上文)

现在在其他类main()创建Test对象并尝试访问变量..



如果Test1& Test2是可以接受的 - 公共

Test1& Test3是可以接受的 - 受保护的

Test1& Test4是可以访问的 - 私人的



谢谢



Create one class Test and create variable (see above)
Now in other class main() create object of Test and try to acess Variable..

If Test1 & Test2 is acessable - public
Test1 & Test3 is acessable - protected
Test1 & Test4 is acessable - private

Thanks


在大多数情况下,默认访问是私人,包括您询问的类型的字段声明。



顶级类,结构或接口的默认访问权限,即在此示例中

In most cases the default access is private, including field declarations of the type you ask about.

The default access for a top level class, struct or interface, i.e. as in this example
namespace Test {
 class NoAccessModifier { }
}



... internal 。但请注意,嵌套类/ struct /接口(即在另一个类中声明的接口)的默认访问权限是私有的,就像在类中定义的字段,方法等一样。)


... is internal. Note however that the default access for a nested class/struct/interface (i.e. one which is declared inside another class) is private, just like fields, methods etc defined inside a class).


这篇关于变量的默认类型。访问修饰符我的意思是。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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