❔ More details on the equivelent of modules in c#?
In Python and Javascipt, I can have modules and packages and must import them to access stuff within them.
It seems the C# equivalent is namespaces. I think I get the basic idea.
It seems that if I don't place something within a namespace, it is accessible everywhere within the project. Meanwhile, placing stuff within a namespace means the namespace itself is accessible everywhere. Is that all there is to the 'accessibility' of top-level names across files? If not, where can I find details? (I don't really know the specific terms to use, hope that was comprehensible)
10 Replies
Well, you can also have multiple projects
And while namespaces might be available everywhere, classes from within them don't have to be
Well, in case of using a separate project, at least
I see. Where can I find more details on how this kind of 'visibility' works? I manually tried out if a class was accessible from another file and stuff. I spent some times googling but haven't really found anything.
Access Modifiers - C# Programming Guide
All types and type members in C# have an accessibility level which controls whether they can be used from other code. Review this list of access modifiers.
thanks. not sure if it covers what i'm looking for. i mean nothing about accessing across files foe example
Files don't matter in C#
Not in the slightest
Namespaces do
The closest thing to 'modules' in C# are projects. A project is a single root directory containing a
.csproj
file. That project may then be published as a library and referenced through a Nuget package reference, or just reference through a relative file path. Namespaces and files literally do not matter in any sense of the word, they're nothing more than ways to conveniently structure and organize your classes.
Namespaces are like folders on your computer, they do nothing more than organize files. You could just put everything on your desktop if you wanted to.or just references through a relative file pathhow would I do that? found something quite different on SO
<ProjectReference Include="Path/To/Project.csproj"/>
Add that in your .csproj
file, or you can add it in VS or Rider automatically.Thanks both of you for the answers
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.