Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
VB
Dim frm As Form
Dim formName As String = "frmNewForm"
frm = DirectCast([Assembly].GetEntryAssembly.CreateInstance(formName), Form)


how to convert this vb code to c# code please help.
Posted
Updated 25-Jun-14 2:49am
v2
Comments
Pravin Patil, Mumbai 25-Jun-14 8:53am    
C# Equivalent of above code -
Form frm = default(Form);
string formName = "frmNewForm";
frm = (Form)Assembly.GetEntryAssembly.CreateInstance(formName);

Converted using http://www.developerfusion.com/tools/convert/vb-to-csharp
BIBASWAN 25-Jun-14 8:59am    
have also converted it from http://www.developerfusion.com but main problem is in
frm = (Form)Assembly.GetEntryAssembly().CreateInstance(formName); code frm getting null value.i dont know why....
Maciej Los 25-Jun-14 11:35am    
Have you got any form in Assemblies?

Please, read my comment to your comment.

The main problem is not "How to convert vb.net to c#?", but "how to use assemblies?"

Have a look here:
How to: Add or Remove References By Using the Add Reference Dialog Box[^]
Assemblies and the Global Assembly Cache (C# and Visual Basic)[^]
Assembly Class[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Jun-14 13:16pm    
Very good point, which should come first, before "convert" (which is just a translation).
But of course even the translation can be needed sometimes.
And, of course, 5ed.
—SA
Maciej Los 25-Jun-14 14:31pm    
Thank you, Sergey ;)
P.S. I did not get your notification to this answer.
In addition to Solution 1: you can use open-source ILSpy to convert the whole assembly; it will create a reverse-engineered project written in selected language, with great accuracy and quality of the generated code. Please see my past answers (they explain how to use it):
Code Interpretation, C# to VB.NET[^],
Need to convert vb code to c#[^],
FixedPage to ContentPage convert c# code into vb.net[^],
Source Code from a exe[^].

—SA
 
Share this answer
 
v2
Comments
Maciej Los 25-Jun-14 11:42am    
Agree, but i see it in a different way. Please, see my answer.
+5!
Sergey Alexandrovich Kryukov 25-Jun-14 13:16pm    
Thank you, Maciej.
—SA

P.S.: Still not getting all the notifications; was not notified on this your comment, as well as many others.
Two solutions -
1. If it is small code or few files you want to convert from VB to C# then there are many online converter available -
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
http://converter.telerik.com/[^]
http://www.carlosag.net/tools/codetranslator/[^]

If you want to convert entire project from VB.NET to C# then you need a project converter -
http://www.developerfusion.com/tools/convert/bulk/[^]
http://www.tangiblesoftwaresolutions.com/[^]

Hope this helps.
 
Share this answer
 
Comments
BIBASWAN 25-Jun-14 8:58am    
i have also converted it from http://www.developerfusion.com but main problem is in
frm = (Form)Assembly.GetEntryAssembly().CreateInstance(formName); code frm getting null value.i dont know why....
Pravin Patil, Mumbai 25-Jun-14 9:01am    
Try giving full name of the form with namespace and assembly name.
Pravin Patil, Mumbai 25-Jun-14 9:01am    
This link might help you - http://stackoverflow.com/questions/4575881/use-value-of-a-string-to-create-new-form-object
Sergey Alexandrovich Kryukov 25-Jun-14 10:17am    
My 5. I added one more tool, very good to know.
—SA
Maciej Los 25-Jun-14 11:42am    
Agree with Sergey, but i see it in a different way.
+5!

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