Is there any performance benefit to explicitly calling a method directly from a namespace class library rather than using
the namespace?
Here is an example of a situation I'm referring to:
// using
using System.Configuration;
public class MyClass
{
private readonly static string DBConn = ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString;
}
vs.
//explicit
public class MyClass
{
private readonly static string DBConn = System.Configuration.ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString;
}
The biggest advantage of using namespace is that the class names which are declared in one namespace will not clash with the same class names declared in another namespace. It is also referred as named group of classes having common features.
Classes are data types. They are an expanded concept of structures, they can contain data members, but they can also contain functions as members whereas a namespace is simply an abstract way of grouping items together. A namespace cannot be created as an object; think of it more as a naming convention.
Namespace in C++ is the declarative part where the scope of identifiers like functions, the name of types, classes, variables, etc., are declared. The code generally has multiple libraries, and the namespace helps in avoiding the ambiguity that may occur when two identifiers have the same name.
While this practice is okay for example code, pulling in the entire std namespace into the global namespace is not good as it defeats the purpose of namespaces and can lead to name collisions. This situation is called namespace pollution.
No, there isn't any.
The compiler will convert all calls to a class to use the fully qualified name anyway.
This is easy enough to see in the produced IL, using any decompiler.
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