1

I'm moving files in my project and I cannot find clear answer - is namespace connected with location of the file? Do I need to change namespace when moving files?

Zet
  • 571
  • 3
  • 13
  • 31

1 Answers1

0

is namespace connected with location of the file?

Only by convention. It is not required, nor enforced by the compiler or runtime.

Note that in C#, you can nest namespaces, and can declare more than one namespace at any given level of nesting. Obviously only one declared namespace in a file can actually match the file's location. So it would not even be possible to require namespaces to match the file name, without abandoning those features in C#.

Do I need to change namespace when moving files?

No. See above.

You may be interested in related Stack Overflow Q&A's on the topic:

The first two relate to management of files and namespaces when changing the location of source files, while the third is more about generally accepted conventions.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136