C #. net calls the dll compiled by VB.net to show the reverse,
After checking on the internet, I found that the dll of the two could be shared. I tried it for a while before it was successful. I will not mention it. I will directly use the example above. IDE is vs2008.
Compile a class library in VB.net and setProject name(The default value isSolution name). The Code is as follows:
NamespaceTest1 Public ClassCls1 Public Function plus (ByVal a As Double, ByVal B As Double) As Double Plus = a + B * 2 End Function End Class End Namespace |
After the release, remember to confirm the root namespace in the project properties before the release, for example, to form a dll file after the release.
Then, create a C # project, a windows application,Add reference, As shown in, and then write the code.
The Code is as follows:
Using System; Using System. Collections. Generic; Using System. ComponentModel; Using System. Data; Using System. Drawing; Using System. Linq; Using System. Text; Using System. Windows. Forms; UsingVbTestDll. test1; Namespace cccc_use_vb_dll { Public partial class Form1: Form { Public Form1 () { InitializeComponent (); } Cls1 cc = new Cls1 (); Private void button#click (object sender, EventArgs e) { Double a1 = Convert. ToDouble (textBox2.Text ); Double a2 = Convert. ToDouble (textBox3.Text ); Double a =Cc. plus (a1, a2 ); TextBox1.Text = a. ToString (); } } } |
Run successfully, as shown in. After data is input, OK.
Key points are described as follows:
1) package the VB class library with namespace;
2) check that the root namespace in the project attribute of the VB class library is the same as the project name by default. You can also change it in the project attribute;
3) when writing C #, add references first, and then use the using statement to introduce the namespace of the dll file of VB. Remember to write the root namespace, that is, using in this example.VbTestDll. test1 insteadUsingTest1;
4) after applying the dll file according to the above steps, if the dll source code content changesGenerateAnd directly go to the C # project.Start debuggingYou can accept this change without rereferencing it.