1

I have a Xamarin solution with 4 project inside, PCL, Android, IOS and UWP.

This is my PCL'structure:

I would like to know if any classes that I created must be on the same namespace es. SgatMobileV2, or in a different namespace es. SgatMobileV2.Behaviors, SgatMobileV2.Helpers, SgatMobileV2.Models etc..

There are differences between this two method? If yes, what should be the best one?

Thank you!

Hikari
  • 589
  • 7
  • 29
  • What happens when I encounter a scenario like this: I need to store a customer's address as well as a memory address? It would be super nifty if I could just call each `Address`. But, if I put those in the same namespace, then they won't compile. I either have to get funky with the naming of each class--which isn't necessarily a bad thing--or I can use namespaces. – Kenneth K. Nov 09 '17 at 16:28

2 Answers2

4

Namespaces are a way to organize your code. You should be able to use any (or none) system that you want. Many people like to use namespaces that follow the folder hierarchy in their code (this is the Visual Studio default behavior) but it's not strictly necessary.

Jason
  • 86,222
  • 15
  • 131
  • 146
2

It is OK for them to be in different namespaces, however if you are referencing a class from a different namespace, you must add a using statement to the top of the referencing class

using SgatMobileV2.Behaviors;

or fully qualify the class name when using it:

SgatMobileV2.Behaviors.MyBehavior b = new SgatMobileV2.Behaviors.MyBehavior();
Dave Smash
  • 2,941
  • 1
  • 18
  • 38
  • Don't forget Namespace Aliasing! https://stackoverflow.com/questions/505262/c-sharp-namespace-alias-whats-the-point – Edwin Jones Nov 09 '17 at 16:47