C # Assembly generation 05, which contains multiple modules

Source: Internet
Author: User

This article contains multiple modules in a program.

 

□Create 3 modules

→ Delete some files in the as folder of drive F, with only three files left

→ Open the myfirstmodule. CS file in notepad, modify the file as follows, and save

using System;
public class MyFirstModule
{
    public static void Hello()
    {
Console. writeline ("Greetings from Module 1 ~ ");
    }
}


→ Open the mysecondmodule. CS file in notepad, modify the file as follows, and save

using System;
public class MySecondModule
{
    public static void Hello()
    {
Console. writeline ("Greetings from module 2 ~ ");
    }
}


→ Compile myfirstmodule. CS class into Module

→ Compile mysecondmodule. CS class into Module

→ Create the mythirdmodule. CS file in the as folder of drive F, open it in notepad, write the following code, and save

using System;
public class MyThirdModule
{
    public static void Hello()
    {
Console. writeline ("Greetings from Module 3 ~ ");
    }
}


→ Compile mythirdmodule. CS class into Module

 

□Create two assemblies and reference them for running

Now we need to create two sets, one containing myfirstmodule and mysecondmodule. Another Assembly contains mysecondmodule and mythirdmodule.

→ Create Assembly AssemblyA. dll including myfirstmodule and mysecondmodule.

→ Create Assembly Assemblyb. dll including mysecondmodule and mythirdmodule.

→ Compile the mainclass. CS file and reference the AssemblyA. dll assembly.

The above doscommand is equivalent to: CSC/R: AssemblyA. dll/out: mainclass.exe mainclass. CS
→Run mainclass.exe

→ Modify the mainclass. CS File

using System;
using System;
class MainClass
{
    static void Main()
    {
        MySecondModule.Hello();
        MyThirdModule.Hello();
    }
}

→ Compile mainclass. CS and apply Assemblyb. dll assembly

→Run mainclassanother.exe

 

Summary: An assembly can contain multiple modules. If you place less commonly used code in a separate module, you can reduce the assembly loading time. If you download an Assembly over the network, you can also save bandwidth.

 

"C # Assembly series" includes:

C # Assembly series 01, use NotePad to write C # And il code, use the DOS command to compile the assembly, and run the C # Assembly series 02 program, use NotePad to view the Il code C # Assembly series 03 of the executable assembly, reference multiple Module C # Assembly series 04, understand the keyword internal C # Assembly generation 05 when the Assembly contains multiple modules, so that the Assembly contains multiple modules

 

References:

Http://www.computersciencevideos.org/created by Jamie King

C # Assembly generation 05, which contains multiple modules

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.