I am being introduced to the C# language (pretty sure it's .NET framework also but this may be irrelevant) at my work. I am using Jetbrains/Rider as my IDE (however this is also probably irrelevant).
My question is an obvious one to anyone looking at the code. I see folders which have dots in the name. I also see that the references to these files in the code use dot notation to denote the file hierarchy. My question is, what happens when there is a conflict which is definitely possible given this structure.
Here is an example: (a made up one not from our code)
Actual file structure (indentations denote sub-folders, f denotes folder):
MyApp (f)
Main (f)
Stuff.cs
Core.cs
MyApp.Main (f)
Stuff.cs
MyApp.Main.Stuff (f)
MoreStuff.cs
This file structure is obviously ridiculous but I see no reason why it coudn't be done this way. Now what if you reference the Stuff.cs file this way
using MyApp.Main.Stuff;
namespace MyApp.Main
{
//whatever
}
How does C# resolve this?
CodePudding user response:
The folder structure and file names don't matter. The namespaces and class names are what matter.
There are some exceptions, like the App_Data
and App_Code
folders, and Global.asax
file in ASP.NET, and the Main
method in console apps.
However, matching the class name to the file name and the namespace to the folder structure makes it much easier to find the right file in your project, particularly in bigger projects.