I am building a game and have several gro开发者_运维百科ups of namespaces. One is called "Engine" the other called "Game". There are several functions and variables that I only want Engine to be able to see. What do I need to do to hide certain functions (not whole classes) from the Game namespace.
C# doesn't have any access modifiers which refer to namespaces.
Instead, perhaps you should put your types into different assemblies - then use the internal
access modifier to limit access to the assembly in which a type or member is declared.
Additionally, if you want a type which is only relevant to one other type, you can nest it and make it private:
internal class Outer
{
// Only the Outer class knows about Nested.
private class Nested
{
}
}
Use private
access specifier.
精彩评论