C # Assembly generation 05. Let the Assembly contain multiple modules,

Source: Internet
Author: User

C # Assembly generation 05. Let the Assembly contain multiple modules,

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 Language & |! What are

& Is the address fetch operator used to extract the address of a variable.
For example, if you define a variable, the system will allocate a space in the memory during compilation.
The location of the space in the memory is its address. & Extract its address.
E. g int a; assign an address to it during compilation, for example, 2000; & a is 2000.
If an integer pointer Variable p, p = & a; is defined, the address 2000 of a is assigned to p. P = 2000 after running.
Another example is scanf ("% d", & a). When you enter 3, it first knows the address of a according to & a, and finds the space of a in the memory by the address, write 3 to this space.
* Is a pointer operator, which is opposite to &. It extracts the value of a Variable Based on the address of the variable.
For example, * the value of a is 3 of variable.
The following is a summary of the pointer used in the definition and description.
Int * p; defines a pointer to integer data.
Int * p [n]; defines the pointer array p, which consists of n pointer elements pointing to integer data.
Int (* p) [n]; p is the pointer variable pointing to a one-dimensional array containing n elements.
Int * p (); p is the function that returns a pointer pointing to integer data.
Int (* p) (); p is the pointer to the function. This function returns an integer value.
Int ** p; p is a pointer variable that points to an integer Data Pointer variable.
If you want to learn more about the system, you can refer to tan haoqiang's c Programming (the third edition), which is easy to understand. Is a good C language learning material.

C Language & |! What are

& Is the address fetch operator used to extract the address of a variable.
For example, if you define a variable, the system will allocate a space in the memory during compilation.
The location of the space in the memory is its address. & Extract its address.
E. g int a; assign an address to it during compilation, for example, 2000; & a is 2000.
If an integer pointer Variable p, p = & a; is defined, the address 2000 of a is assigned to p. P = 2000 after running.
Another example is scanf ("% d", & a). When you enter 3, it first knows the address of a according to & a, and finds the space of a in the memory by the address, write 3 to this space.
* Is a pointer operator, which is opposite to &. It extracts the value of a Variable Based on the address of the variable.
For example, * the value of a is 3 of variable.
The following is a summary of the pointer used in the definition and description.
Int * p; defines a pointer to integer data.
Int * p [n]; defines the pointer array p, which consists of n pointer elements pointing to integer data.
Int (* p) [n]; p is the pointer variable pointing to a one-dimensional array containing n elements.
Int * p (); p is the function that returns a pointer pointing to integer data.
Int (* p) (); p is the pointer to the function. This function returns an integer value.
Int ** p; p is a pointer variable that points to an integer Data Pointer variable.
If you want to learn more about the system, you can refer to tan haoqiang's c Programming (the third edition), which is easy to understand. Is a good C language learning material.

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.