C # Assembly series 01, use NotePad to write C # And il code, use the DOS command to compile the assembly, and run the program

Source: Internet
Author: User
Tags mscorlib

This article describes how to compile C # And il code and use the "vs2012 developer command prompt" to compile the code into an assembly and run the program.

 

□C # compile the file as an assembly

→ Create an as folder on drive F
→ Create myclass. Cs in the as folder
→ Open and write the following code in notepad and save

using System;
public class MyClass
{
    public static void PrintSth()
    {
        Console.WriteLine("Hello");
    }
}

→ Open "vs2012 developer command prompt", enter the following command, and press ENTER

→ Run the following command to compile myclass. cs into the myclass. dll Assembly file, and press ENTER

View the as folder under drive F. An additional myclass. dll assembly is added.

 

□Il file compiled into assembly

→ Create secondclass. Il in the as folder
→ Open and write the following code in notepad and save

.assembly SecondClassAssembly {}
.assembly extern mscorlib {}
.class public SecondClass extends [mscorlib]system.object{
    .method public static void PrintSth() cil managed{
        ldstr "hello from IL"
        call void [mscorlib]System.Console::WriteLine(string)
        ret
    }
}

→ Enter the following command:

→ Press enter to see the following page:

In the as folder under drive F, a secondclassassembly. dll assembly is added.

→ View the DLL file in the as folder, enter the following command, and press ENTER

 

□Use the Assembly to run the program

→ Create mainclass. Cs in the as folder
→ Open and write the following code in notepad and save

using System;
class MainClass
{
    static void Main()
    {
        MyClass.PrintSth();
    }
}

→ Open "vs2012 developer command prompt", enter the following command, and press ENTER


In the asfile folder under the fdisk, A mainclass.exe assembly is added.

→ Enter the following command and press Enter.

 

 

 

C # Assembly series 01, use NotePad to write C # And il code, use the DOS command to compile the assembly, and run the program

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.