Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
public static class UnaryFunctions
    {
        public static UnaryFunction Identity() {
            return new UnaryFunction(delegate(double x) { return x; });
        }
     }


I'd like to change this code(original in C#) to VB.NET however i have no idea how to do it. Could someone help me?
Thanks
Posted

It's not good to answer such questions in each particular situation, there are too many of them.

You can translate any C# code to VB.NET and visa versa by yourself, automatically.

You can use Reflector or its open-source replacement ILSpy or one of similar tools:
http://en.wikipedia.org/wiki/.NET_Reflector[^],
http://ilspy.net/[^].

Additionally, this is one of effective tools to learn CIL. It can be very useful, and I don't know a good reference on the language. CIL knowledge is very important, in particular, for using System.Reflection.Emit, an extremely powerful library.

You can write code in one language, compile it, load the assembly with ILSpy, choose another language, and decompile the code part you need. The accuracy of the results is very good.

This is a stand-along open-source code convertor: http://codeconvert.codeplex.com/[^].

There is a number of on-line tools:
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^],
http://converter.telerik.com/[^] (in my observations, this one is better).

You can find more: http://bit.ly/XFdX2G[^].

In some more complex cases, the accuracy can be questionable.

—SA
 
Share this answer
 
Comments
Manfred Rudolf Bihy 31-May-13 9:14am    
Great links. I like Reflector a lot! 5+
Sergey Alexandrovich Kryukov 31-May-13 9:21am    
Thank you, Manfred.

Pay attention: not just Reflector, but also its open-source analog, ILSpy. Reflector is going out of support and does not have open source, ILSpy is taking over (very few features are missing at the moment: some .NET languages, only IL, C# and VB.NET are currently supported, everything else is the same or even better).

—SA
Dave Kreskowiak 31-May-13 10:37am    
"Going out of support"??? No it's not. It's been converted to a commercial product as of version 7.0.
Sergey Alexandrovich Kryukov 31-May-13 10:44am    
Ah, OK, I guess you know better. Sorry for this inaccuracy. Anyway, ILSpy has apparent value as open source. Where else you can see how decompilation is implemented?

Thank you for the note,
—SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-May-13 8:59am    
It's a good idea to answer in general way, my 5. (Who was so clever to vote 3?)

From my side, I added another universal answer, how to translate code automatically. Not only online.
Please see Solution 4.

—SA
Public NotInheritable Class UnaryFunctions
Private Sub New()
End Sub
Public Shared Function Identity() As UnaryFunction
Return New UnaryFunction(Function(x As Double) x)
End Function
End Class
 
Share this answer
 
Comments
sherlock_cc 31-May-13 8:46am    
Another Question How Should i understand this code? i have just started to learn VB.NET and Csharp
Dave Kreskowiak 31-May-13 10:33am    
After looking at the OP's comment, now you know why you don't just give a straight up answer. You've actually taught the OP nothing.

Give a man a fish, he'll eat for a day. TEACH a man to fish and he can eat for a lifetime.
Hi,

Please follow below link and you will get your solution:-

http://www.paeros.com/Home/Question?questionId=25[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900