Note that there are some explanatory texts on larger screens.

plurals
  1. POConfused about VB/C# conversion with event handlers
    text
    copied!<p>I've used just about every conversion tool out there to convert a snippet of <a href="http://en.wikipedia.org/wiki/Visual_Basic_.NET" rel="nofollow">VB.NET</a> to C#. Aside from some differences in conversion, the one thing that I am having trouble grasping is event handler conversion. Looking at some pure C# code, I see things like this:</p> <pre><code>protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); ... } </code></pre> <p>which looking at <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.onprerender.aspx" rel="nofollow">MSDN</a>, raises the PreRender event. OK. Now, taking some VB.NET code:</p> <pre><code>Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender .... EndSub </code></pre> <p>which handles the same PreRender event and translating it with a conversion tool (<a href="http://www.developerfusion.com/tools/convert/vb-to-csharp/" rel="nofollow">DeveloperFusion seemed to give the cleanest conversion of the Event Handler)</a> gave this result:</p> <pre><code>public class MyClass : UserControl { private void Page_PreRender(object sender, System.EventArgs e) { ... } public MyClass() { PreRender += Page_PreRender; } } </code></pre> <p>Being new to this, my main question is whether or not the original (or pure) C# code first listed above is basically the same as the converted C# code (other than maybe with the <code>object sender</code> portion)? And if not a brief explanation would be much appreciated.</p> <p>Essentially, I am just wondering whether the <code>PreRender += Page_PreRender;</code> portion is superfluous.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload