Hello Everyone and thanks for your help in advance. I am rewriting some C#code to Vb.Net and have used some of the conversion sites. However, one line of code does not appear to be converting correctly and I don't understand it enough to rewrite it. The
line is:
public event RenderEvent BeforeRender = (writer, document) => { };
Thanks again for the response. So if I understand correctly the code I am trying to convert => {} simply means perform the function. Is that correct? So when I use the code
Public Event BeforeRender As RenderEvent = Function(writer, document)
End Function
Intellisense tells me and end of statement is expected and that End Function must be preceded by a Function. What am I missing?
Please take note, code converters albeit great are really weak on converting C# lambdas and Anonymous functions to VB.NET (or the inverse). For these types of conversions you are going to need some in-depth understanding of these topics. To add on to the
explinations previously given in this thread, you may want to read up on the following, because understanding Lambdas and Anonymous functions is not like needing to understand simple syntax type conversions you normally run across.
Tools for Converting C# code to VB.NET (or vice versa) and a little => ... Function(), Lambdas too:
kmcnet
Participant
1090 Points
652 Posts
C# to VB.Net
Sep 23, 2011 11:35 PM|LINK
Hello Everyone and thanks for your help in advance. I am rewriting some C#code to Vb.Net and have used some of the conversion sites. However, one line of code does not appear to be converting correctly and I don't understand it enough to rewrite it. The line is:
public event RenderEvent BeforeRender = (writer, document) => { };
Any help would be greatly appreciated.
Careed
All-Star
18764 Points
3637 Posts
Re: C# to VB.Net
Sep 24, 2011 01:56 AM|LINK
Try this:
"The oxen are slow, but the earth is patient."
kmcnet
Participant
1090 Points
652 Posts
Re: C# to VB.Net
Sep 24, 2011 03:02 AM|LINK
Thanks for the response. Part of the problem is I don't understand what is supposed to be in between the angle brackets.
Horizon_Net
Star
8277 Points
1435 Posts
Re: C# to VB.Net
Sep 24, 2011 11:52 AM|LINK
Hi,
for further conversions just use the code converter from Telerik - http://converter.telerik.com/
If my post solves your problem, please mark as answer.
Careed
All-Star
18764 Points
3637 Posts
Re: C# to VB.Net
Sep 24, 2011 02:50 PM|LINK
You are using a lambda expression which represents an anonymous method. For example, the following is a lambda expression in C#:
The above can be used to pass in any numeric value to produce its square.
The equivalent expression in VB is:
To learn more about lambda expressions, try these:
For C#: http://msdn.microsoft.com/en-us/library/bb397687.aspx
For VB: http://msdn.microsoft.com/en-us/library/bb531253.aspx
"The oxen are slow, but the earth is patient."
kmcnet
Participant
1090 Points
652 Posts
Re: C# to VB.Net
Sep 25, 2011 12:32 PM|LINK
Thanks again for the response. So if I understand correctly the code I am trying to convert => {} simply means perform the function. Is that correct? So when I use the code
Public Event BeforeRender As RenderEvent = Function(writer, document)
End Function
Intellisense tells me and end of statement is expected and that End Function must be preceded by a Function. What am I missing?
rossmc1
Member
644 Points
152 Posts
Re: C# to VB.Net
Sep 26, 2011 04:47 PM|LINK
try this code convertor
http://www.developerfusion.com/tools/
its very powerful for that kind of thing
atconway
All-Star
16846 Points
2756 Posts
Re: C# to VB.Net
Sep 27, 2011 08:05 PM|LINK
Please take note, code converters albeit great are really weak on converting C# lambdas and Anonymous functions to VB.NET (or the inverse). For these types of conversions you are going to need some in-depth understanding of these topics. To add on to the explinations previously given in this thread, you may want to read up on the following, because understanding Lambdas and Anonymous functions is not like needing to understand simple syntax type conversions you normally run across.
Tools for Converting C# code to VB.NET (or vice versa) and a little => ... Function(), Lambdas too:
http://allen-conway-dotnet.blogspot.com/2009/11/tools-for-converting-c-code-to-vbnet-or.html
Lambda Expressions (Visual Basic)
http://msdn.microsoft.com/en-us/library/bb531253.aspx
David Anton
Contributor
3704 Points
638 Posts
Re: C# to VB.Net
Sep 28, 2011 03:31 PM|LINK
Unfortunately, even in VS 2010 VB does not allow you to initialize events in their declaration, using lambdas or not.
Here's a work-around for you:
http://www.tangiblesoftwaresolutions.com
Instant C# - VB to C# Converter
Instant VB - C# to VB Converter