Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 接口引用找不到所需的类_C#_Interface - Fatal编程技术网

C# 接口引用找不到所需的类

C# 接口引用找不到所需的类,c#,interface,C#,Interface,一般来说,我对编程相当陌生,在尝试理解和使用C#中的接口时遇到了一个问题 我有一个GUI类,叫做MainWindow。该类实现了一个名为IClientView的接口。另一个类ClientController使用此接口更新MainWindow中的字段 然而,它并没有像我预期的那样工作,因为在ClientController中对我的接口的引用总是空的,我不明白为什么 这是部分代码,任何帮助都将不胜感激 class ClientController : IClientController {

一般来说,我对编程相当陌生,在尝试理解和使用C#中的接口时遇到了一个问题

我有一个GUI类,叫做MainWindow。该类实现了一个名为IClientView的接口。另一个类ClientController使用此接口更新MainWindow中的字段

然而,它并没有像我预期的那样工作,因为在ClientController中对我的接口的引用总是空的,我不明白为什么

这是部分代码,任何帮助都将不胜感激

class ClientController : IClientController
{
    public IClientView ViewForm { get; set; }
}

public interface IClientView
{
    /// <summary>
    /// Updates the status window.
    /// </summary>
    /// <param name="status">Updates the status view.</param>
    void StatusWindow(string status);
}

public partial class MainWindow : Window, ILoginFormView, IClientView
{
    #region IClientView implementation

    public void StatusWindow(string status)
    {
        clientInfoTextBlock.Text += status +"\n";
    }

    #endregion
}
类ClientController:IClientController
{
公共IClientView视图窗体{get;set;}
}
公共接口IClientView
{
/// 
///更新状态窗口。
/// 
///更新状态视图。
无效状态窗口(字符串状态);
}
公共部分类主窗口:窗口、ILoginFormView、IClientView
{
#区域IClientView实现
公共无效状态窗口(字符串状态)
{
clientInfoTextBlock.Text+=状态+“\n”;
}
#端区
}
编辑:

我应该补充一点,我有另一个接口,它将处理登录,ClientController类以同样的方式引用它,并由MainWindow类实现,并且这个接口可以工作。我就是想不出两者之间的区别:

class ClientController: IClientController 
{
    #region private fields

    /// <summary>
    /// Reference to login form
    /// </summary>
    public ILoginFormView LoginForm 
    {
        get;
        set;
    }
}

public interface ILoginFormView 
{
    /// <summary>
    /// IP address of server to connect to
    /// </summary>
    string ServerIpAddress 
    {
        get;
    }

    /// <summary>
    /// TCP port number of server to connect to
    /// </summary>
    int ServerTcpPort 
    {
        get;
    }
}

public partial class MainWindow: Window, ILoginFormView, IClientView 
{
    #region ILoginFormView implementation

    /// <summary>
    /// IP address of server to connect to.
    /// </summary>
    public string ServerIpAddress 
    {
        get 
        {
            return (string) Dispatcher.Invoke(new Func<string>( () => serverAddressBox.Text));
        }
    }

    /// <summary>
    /// TCP port of the server to connect to.
    /// </summary>
    public int ServerTcpPort 
    {
        get 
        {
             return (int) Dispatcher.Invoke(new Func<int>( () => Convert.ToInt32(serverPortBox.Text)));
        }
    }

    #endregion
}
类ClientController:IClientController
{
#区域专用字段
/// 
///登录表单的引用
/// 
公共ILoginFormView登录表单
{
得到;
设置
}
}
公共界面ILoginFormView
{
/// 
///要连接到的服务器的IP地址
/// 
字符串服务器IP地址
{
得到;
}
/// 
///要连接到的服务器的TCP端口号
/// 
int服务器支持
{
得到;
}
}
公共部分类主窗口:窗口、ILoginFormView、IClientView
{
#区域ILoginFormView实现
/// 
///要连接到的服务器的IP地址。
/// 
公共字符串服务器IP地址
{
得到
{
return(string)Dispatcher.Invoke(newfunc(()=>serverAddressBox.Text));
}
}
/// 
///要连接到的服务器的TCP端口。
/// 
公共int服务器支持
{
得到
{
return(int)Dispatcher.Invoke(newfunc(()=>Convert.ToInt32(serverPortBox.Text));
}
}
#端区
}

代码段不适用于C#。这是用于JS/HTML/CSS.Post
ClientController.ViewForm
初始化代码的。@丹尼斯我怀疑没有初始化,这就是问题所在。@PeterSchneider抱歉,但我不确定你的意思。ClientController端的初始化代码,但据我所知,我已经完成了与w相同的操作。ILoginFormView接口,并且该接口有效。