Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.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# 如何在VB.net中实现这样的接口_C#_Asp.net_Vb.net - Fatal编程技术网

C# 如何在VB.net中实现这样的接口

C# 如何在VB.net中实现这样的接口,c#,asp.net,vb.net,C#,Asp.net,Vb.net,在C#项目中,我有这样一个界面: public interface IView { event EventHandler Load; } public partial class LoginUserControl : UserControl, IView { protected void Page_Load(object sender, EventArgs e) { } } Partial Public Class LoginUserControl I

在C#项目中,我有这样一个界面:

public interface IView
{
    event EventHandler Load;
}
public partial class LoginUserControl : UserControl, IView
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}
Partial Public Class LoginUserControl
    Inherits UserControl
    Implements IView

    Protected Sub Page_Load(sender As Object, e As EventArgs)

    End Sub
End Class
我在webforms的用户控件中实现它,如下所示:

public interface IView
{
    event EventHandler Load;
}
public partial class LoginUserControl : UserControl, IView
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}
Partial Public Class LoginUserControl
    Inherits UserControl
    Implements IView

    Protected Sub Page_Load(sender As Object, e As EventArgs)

    End Sub
End Class
因为UserControl的基本控件具有事件调用负载,所以我不需要在LoginUserControl中写入任何内容

但是,在vb.net中,我声明的界面如下:

Public Interface IView
    Event Load As EventHandler
End Interface
此外,LoginUserControl如下所示:

public interface IView
{
    event EventHandler Load;
}
public partial class LoginUserControl : UserControl, IView
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}
Partial Public Class LoginUserControl
    Inherits UserControl
    Implements IView

    Protected Sub Page_Load(sender As Object, e As EventArgs)

    End Sub
End Class
它无法构建,因为缺少实现。但我补充说

Public Event Load As EventHandler Implements IView.Load
比如说, 与基类冲突,应声明为“Shadow”

我怎么办

更新12/18

我不想对基类事件进行阴影处理。 我只想要像c#一样的行为

比如说

我有一门课:

class A : IView 
然后我必须实现Load事件。 但如果我有课:

class B : Control, IView
基类控件具有相同的名称加载, 我不需要在B中实现任何东西

更新12/18

哦,是的,这就是解决办法。但是,它看起来很像民谣。
但是,谢谢大家。

如果使用与基类中定义的元素相同的名称声明元素。在这种情况下,该类中的元素应该与基类元素形成阴影。 因此,您可以在这里向声明中添加Shadows关键字,或者更改要声明的元素的名称

Partial Public Class LoginUserControl
    Inherits System.Web.UI.UserControl
    Implements IView
    Public Shadows Event Load As EventHandler Implements IView.Load
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

End Class


Public Interface IView
    Event Load As EventHandler
End Interface

如果使用与基类中定义的元素相同的名称声明元素。在这种情况下,该类中的元素应该与基类元素形成阴影。 因此,您可以在这里向声明中添加Shadows关键字,或者更改要声明的元素的名称

Partial Public Class LoginUserControl
    Inherits System.Web.UI.UserControl
    Implements IView
    Public Shadows Event Load As EventHandler Implements IView.Load
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

End Class


Public Interface IView
    Event Load As EventHandler
End Interface

您不需要使用“阴影”-只需在实现以下功能时更改名称:

Private Event IView_Load As EventHandler Implements IView.Load

您的类仍然实现了IView.Load,当通过IView实例访问时,您仍然可以使用名称“Load”

您不需要使用“Shadows”-只需在实现时更改名称即可:

Private Event IView_Load As EventHandler Implements IView.Load

您的类仍然实现IView.Load,并且当通过IView实例访问时,您仍然可以使用名称“Load”

否,我不想隐藏基类事件。请看我的更新。@GeminiYellow:我认为VB.Net不允许像C#这样的隐式接口实现,因此您解释的代码与VB.Net没有直接的关联。因此,我在vb.net中能想到的最接近的方法就是使用“Shadows”关键字。谢谢你的帮助。你能发布一些解决方案的代码吗?我真的不知道如何编写vb.net。如果使用阴影,基类加载将被隐藏,对吗?以及如何同时启动IView.Load和Control.Load事件。@GeminiYellow:即使我在vb.net上也不是很舒服。但是我认为您可以通过创建一些包装器类来定制它。我可以在()上看到类似的问题不,我不想隐藏基类事件。看我的更新。@GeminiYellow:我认为VB.Net不允许像C#这样的隐式接口实现,因此像你解释的一样的代码与VB.Net没有直接的关联。因此,我在vb.net中能想到的最接近的方法就是使用“Shadows”关键字。谢谢你的帮助。你能发布一些解决方案的代码吗?我真的不知道如何编写vb.net。如果使用阴影,基类加载将被隐藏,对吗?以及如何同时启动IView.Load和Control.Load事件。@GeminiYellow:即使我在vb.net上也不是很舒服。但是我认为您可以通过创建一些包装器类来定制它。我可以在()