C #. net calls the dll compiled by VB.net to show the reverse,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.