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?
Same thing. Use any one you like more. I use using
, and fallback to full names when name collision occurs.
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]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With