开发者

C#: Why do I have to use the public access modifier in class's vars?

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).


Because you can not read? Ok, joking aside. You said you are a eginner, so this is totally normal to overlook small things.

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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜