Is for example this
using SportsStore.Domain.Entities;
better than this
using SportsStore;
?
If that is the case, what does it mean for the performance of my program when I import bigger libraries?
Edit: I mean, I get that it is pointless to import stuff I donĀ“t use, but is there any actual harm in doing so?
They're entirely different. A using
directive of that form only tells the compiler to make members of the given namespace available as simple names. It has no effect at execution time - if you didn't have any using
directives and just referred to everything by the full name, you'd end up with the same code. As "nested" namespaces aren't imported, just using SportsStore
won't import members of the SportsStore.Domain.Entities
namespace.
(Using directives also make extension methods declared in types within the given namespace available, btw.)
As a rule of thumb, have using
directives for everything you need to (in order to keep the bulk of your code simple) but no more than that, just to avoid cluttering your code unnecessarily. Visual Studio has a command to sort using directives alphabetically and remove unnecessary ones - I have that bound to Ctrl+Shift+U which I use fairly frequently.
See more on this question at Stackoverflow