我已經創建了下面的類:爲什麼我不得不使用完整的命名空間?
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
}
}
爲什麼我被迫在var optionX = MyArgParser.MyArgParser.GetOptionValue("optionX");
,而不是僅僅MyArgParser.GetOptionValue("optionX");
使用完整的命名空間爲MyArgParser
類?
using MyUtils.MyArgParser;
被忽略。不管它有沒有不會有什麼區別,編譯器仍然強迫我使用完整的命名空間。
我覺得這很奇怪,因爲它並沒有到處發生。例如,我不需要在定義應用程序入口點的文件中使用完整的名稱空間。
因爲您自己命名它與命名空間 – Patrick
@Patrick I相同,但爲什麼它不會強制我在程序的其他部分使用完整的命名空間,就像在主程序文件中一樣? – IneedHelp