How can I retrieve the namespace to a string C#

This should work:

var myType = typeof(MyClass);
var n = myType.Namespace;

Write out to the console:

Type myType = typeof(MyClass);
Console.WriteLine("Namespace: {0}.", myType.Namespace);

Setting a WinForm label:

Type myType = typeof(MyClass);
namespaceLabel.Text = myType.Namespace;

Or create a method in the relevant class and use anywhere:

public string GetThisNamespace()
{
   return GetType().Namespace;
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)