我正在學習WCF,並在簡單的WCF示例上找到了this article。爲什麼System.ServiceModel.Dispatcher需要完全限定編譯
在下面的代碼中(來自上面的文章),爲什麼當foreach循環中的System.ServiceModel.Dispatcher.ChannelDispatcher
需要在有using System.ServiceModel;
時完全合格?雖然ServiceHost
不需要完全限定它的工作方式,但它與Dispatcher
的命名空間相同。
如果您在循環中從System.ServiceModel.Dispatcher.ChannelDispatcher
中刪除System.ServiceModel
,則代碼不會編譯。
using System;
using System.ServiceModel;
namespace ConsoleHost
{
class Program
{
static void Main(string[] args)
{
Type serviceType = typeof(EmailService.EmailValidator);
Uri serviceUri = new Uri("http://localhost:8080/");
ServiceHost host = new ServiceHost(serviceType, serviceUri);
host.Open();
foreach (System.ServiceModel.Dispatcher.ChannelDispatcher dispatcher in host.ChannelDispatchers)
{
Console.WriteLine("\t{0}, {1}", dispatcher.Listener.Uri.ToString(), dispatcher.BindingName);
}
}
}
}
因爲'Dispatcher'不是一個類,它不能通過另一個命名空間有一個快捷方式?我想我誤解使用塊是所有事物的捷徑,而不僅僅是類。這很有意義,因爲在許多情況下,除了使用System之外,您不必再使用任何其他'using'語句;'謝謝。 – Jim