我怎样才能检索命名空间为字符串C# [英] How can I retrieve the namespace to a string C#
问题描述
我写一个程序,需要程序的命名空间,但我似乎无法弄清楚如何找回它。我想最终的结果是在一个字符串。
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.
我能够找到的有关这个主题的MSDN页面,但事实证明这是无助于自己。
http://msdn.microsoft.com/en-us/library/ system.type.namespace.aspx
I was able to find an MSDN page about this topic but it proved to be unhelpful to myself. http://msdn.microsoft.com/en-us/library/system.type.namespace.aspx
任何帮助,将不胜感激。该程序是用C#
Any help would be appreciated. The program is written in C#.
编辑:对不起,伙计们,这不是一个控制台应用程序
Sorry guys, this is not a console application.
推荐答案
当你做了什么事以下内容:
What happened when you did the following:
Type myType = typeof(MyClass);
// Get the namespace of the myClass class.
Console.WriteLine("Namespace: {0}.", myType.Namespace);
这应该工作...
在一个字符串:
Type myType = typeof(MyClass);
var n = myType.Namespace;
WinForm的标签:
WinForm label:
Type myType = typeof(MyClass);
namespaceLabel.Text = myType.Namespace;
这篇关于我怎样才能检索命名空间为字符串C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!