How can I retrieve the namespace to a string C#

后端 未结 9 1006
一向
一向 2020-12-15 02:38

I am writing a program which needs the namespace of the program but I cant seem to figure out how to retrieve it. I would like the end result to be in a string.

I wa

9条回答
  •  无人及你
    2020-12-15 02:57

    Type myType = typeof(MyClass);
    // Get the namespace of the myClass class.
    Console.WriteLine("Namespace: {0}.", myType.Namespace);
    

    Building on Joe's comment you can still use

    Type myType = typeof(MyClass);
    // Get the namespace of the myClass class.
    var namespaceName = myType.Namespace.ToString();
    

    with namespaceName being a variable to access the namespace name as a string value.

提交回复
热议问题