Theoretical question: is it any difference between doing this:
using System;
...
var foo = new String("foo");
and this:
var foo = new System.String("foo");
DLL loading? A performance difference?
Mainly, my doubt is what's the best code practice in this situation?
No, they'll be compiled to absolutely identical IL.
The using
directive (there's no such term as "namespace accessor") is just a way of telling the C# compiler that it should look in that namespace when trying to resolve simple names to fully-qualified ones.
(Of course both will actually fail to compile as there's no String(String)
constructor in .NET, but that's a different matter.)
Note that using the built-in alias string
is identical to using the System.String
type too - it really is just an alias. For example:
// Just one type!
string x = new String(new char[10]);
See more on this question at Stackoverflow