C
C#17mo ago
custard

❔ 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
Angius
Angius17mo ago
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
custard
custard17mo ago
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.
Angius
Angius17mo ago
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.
custard
custard17mo ago
thanks. not sure if it covers what i'm looking for. i mean nothing about accessing across files foe example
Angius
Angius17mo ago
Files don't matter in C# Not in the slightest Namespaces do
Thinker
Thinker17mo ago
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.
custard
custard17mo ago
or just references through a relative file path
how would I do that? found something quite different on SO
Thinker
Thinker17mo ago
<ProjectReference Include="Path/To/Project.csproj"/> Add that in your .csproj file, or you can add it in VS or Rider automatically.
custard
custard17mo ago
Thanks both of you for the answers
Accord
Accord17mo ago
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.
Want results from more Discord servers?
Add your server
More Posts
❔ what's an object?Can somebody please explain to me in very simple words what's an obkect as I don't understand it fro❔ ASP.NET CALLBACKhello i've got a callback with a JWS signature how would i add a new controller to the site to handl❔ error when converting string to long```cs System.FormatException: Input string was not in a correct format. ``` you can see on image frxamarin errori get this error running xamarin android app on windows running same project on macos works❔ Tell DbProviderFactory what connection string to use not working?```DbProviderFactories.RegisterFactory("System.Data.MySql", MySqlConnectorFactory.Instance); service❔ How can i calculate a rotation float from a direction vector?i know this might not be the correct place to ask such a question, but i figured such a large number❔ How can I better understand the concepts of unit of work and repository pattern in C# .NET 7?I am seeking assistance in understanding the unit of work and repository pattern in C#.NET7. While I❔ Help with a unity Inventoryim making an Inventory for my unity game and im getting this CS1061 error, i Know what the error is,❔ Running an awaitable async Task, but forcing it to run on a specific thread (main thread).Hi everyone, I'm doing some work in Unity and am having an issue where some of the code that I want ❔ Help connect VS-Code to Unity and Simplify running programI want to connect Unity and VS code Also ive done it before but i want to simplify how you run the