ThatsIT.net.au said:
To make things a bit clearer, can someone convert this VB example to C#, I
cant seem to work out the syntax
I have written a translation below each block. Note that I have modified
your event arguments to conform to the established .Net practice of always
providing a "sender" argument and encapsulating all returned information in
a second argument that inherits from EventArgs.
Partial Class test
Inherits System.Web.UI.Page
Dim WithEvents oTest As TestClass = New TestClass
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
oTest.getEvent()
End Sub
Public Sub getevent(ByVal tex As String) Handles oTest.Event1
Label1.Text = tex
End Sub
End Class
public partial class test : System.Web.UI.Page
{
private TestClass oTest;
protected void Page_Load(object sender, EventArgs e)
{
oTest = new TestClass();
oTest.Event1 += new Event1Handler(getevent);
oTest.getEvent();
}
private void getevent(object sender, Event1EventArgs e)
{
Label1.Text = e.s;
}
}
Public Class TestClass
Public Event Event1(ByVal tex As String)
Public Sub getEvent()
Dim e As EventArgs = New EventArgs
RaiseEvent Event1("Wow it works")
End Sub
End Class
public class TextClass
{
public delegate void Event1Handler(object sender, Event1EventArgs e);
public event Event1Handler Event1;
public void getEvent()
{
if (Event1!=null)
{
Event1EventArgs sea = new Event1EventArgs();
sea.s = "Wow it works";
Event1(this, sea);
}
}
}
public class Event1EventArgs: EventArgs
{
public string s;
}