C#:为什么我必须在类的变量中使用 public 访问修饰符?
好吧,好吧,我是初学者,所以..是的,这可能是一个非常愚蠢的问题。 我读到,如果我声明变量或对象,而不提及访问修饰符(公共、私有等),那么它会自动使其具有 Internal 访问修饰符(并且它将存在于当前的任何位置)命名空间)。
那么为什么我需要将一个类中的变量设置为 Public 才能将它们放入另一个类中(当然,例如我的程序的类)。
OK, well, I am a beginner, so.. yeah, this may be a very stupid question.
I read that if I declare variable or object, without mentioniong the access-modifier (public, private, etc.) than it's automatically making it having the Internal acess modifier (and it will exist anywhere in the current namespace).
So why do I need to set my vars in a class as Public to get them in another class (such as my program's class of course).
因为你看不懂?好吧,开个玩笑。你说你是一个白痴,所以忽略小事是很正常的。
啊,不。它默认为私有,NOT为内部。它默认为最合理的默认值,并且内部仍然允许大量跨类访问,从而导致不良的代码实践。
Because you can not read? Ok, joking aside. You said you are a eginner, so this is totally normal to overlook small things.
Ah, no. It defaults to private, NOT to internal. It defaults to the most sensible default, and internal would still allow a lot of cross class accesses that lead to bad code practices.