0

I am building this SportStore app from a book example. Everything works perfectly. But when I look into the code, I realize that the namespace doesn't match the folder path. Then why Visual Studio can still compile and run them example? (as you notice, the difference is the letter "s" in "SportsStore"

namespace

enter image description here

0

1 Answer 1

1

Folder and filenames are ignored by the compiler. All it cares about is the contents of the files. .Net doesn't require folders to match namespaces. Class names are not required to match the filenames, either.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks. btw, why it still can look for the correct class to use?
I don't understand your question. The compiler doesn't look at filenames. It looks at the contents of the files.
@kaboom: the compiler looks for the class by the path defined in .csproj file. After it is compiled and linked into an assembly, the classes are looked up by namespace.
@paulius_l, the path defined in the .csproj file is not used to locate a class. It's only used to define which files are included in compilation. Class names are completely independent of file names.
Sorry, meant to write that classes are located in files referenced by .csproj. I hope that still explained kaboom how does the Visual Studio compilation work, albeit not entirely correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.