我创建了以下类:
using System.Windows;
using System.Windows.Input;
using MyUtils.MyArgParser;
namespace MyUtils.MyImplement
{
public static class ImplementExitOnEscape
{
#region ImplementExitOnEscape
public static void Implement(Window window)
{
window.KeyDown += Window_KeyDown;
}
private static void Window_KeyDown(object sender, KeyEventArgs e)
{
var window = sender as Window;
// Close window when pressing the escape key.
if (e.Key == Key.Escape) if (window != null) window.Close();
var optionX = MyArgParser.MyArgParser.GetOptionValue("optionX");
}
#endregion //ImplementExitOnEscape
}
}
为什么我被迫使用MyArgParser
类的全名空间var optionX = MyArgParser.MyArgParser.GetOptionValue("optionX");
而不是 just MyArgParser.GetOptionValue("optionX");
?
using MyUtils.MyArgParser;
被忽略。有没有它不会有任何区别,编译器仍然强迫我使用完整的命名空间。
我觉得这很奇怪,因为它并非无处不在。例如,我不需要在定义了我的应用程序入口点的文件中使用完整的命名空间。