Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET to C# conversion -- Interface Event declaration for non-EventHandler events

Tags:

c#

.net

vb.net

Ran into this while converting a VB.NET interface to C#; the VB version defines an event which doesn't conform to the typical (object sender, EventArgs e) signature:

VB

Public Class SomeType
    ' Does *NOT* inherit from EventArgs
End Class

Public Interface ISomething
    Public Event SomeEvent(sender as Object, value as SomeType)
End Interface

What's the C# equivalent for ISomething? My attempts so far have failed to compile:

like image 380
STW Avatar asked May 09 '26 17:05

STW


1 Answers

You'll need a delegate type declaration:

public delegate void SomeEventHandler(object sender, SomeType value)

public class SomeType
{
}

public interface ISomething
{
    public event SomeEventHandler SomeEvent;
}

Or in .NET 3.5 you could use the built-in Action type:

public class SomeType
{
}

public interface ISomething
{
    public event Action<object, SomeType> SomeEvent;
}
like image 147
Jon Skeet Avatar answered May 12 '26 06:05

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!