ASP. NET (C #) to generate DLL

Source: Internet
Author: User

Create the following C # code file:
1. MySwap. cs
Using System;
Namespace MyMethods
{
Public class SwapClass
{
Public static bool Swap (ref long I, ref long j)
{
I = I + j;
J = I-j;
I = I-j;
Return true;
}
}
}
2. MyMaxCD. cs
Using System;
Namespace MyMethods
{
Public class MaxCDClass
{
Public static long MaxCD (long I, long j)
{
Long a, B, temp;
If (I> j)
{
A = I;
B = j;
}
Else
{
B = I;
A = j;
}
Temp = a % B;
While (temp! = 0)
{
A = B;
B = temp;
Temp = a % B;
}
Return B;
}
}
}
}

CSC. EXE run: csc/target: library/out: MyDLL. DLL MySwap. cs MyMaxCD. after cs is complete, find the MyDLL we just generated in the directory. DLL file/target: the library compiler option notifies the compiler to output the DLL file instead of the EXE file. The/out compiler option followed by the file name is used to specify the DLL file name. If the/out file is not followed by the file name compiler, use the first file (MySwap. cs) as the DLL file name. The generated file is the MySwap. DLL file.

Create: MyClient. cs file:
Using MyMethods;
Class MyClient
{
Public static void Main (string [] args)
{
If (args. Length! = 2)
{
Console. WriteLine ("Usage: MyClient <num1> <num2> ");
Return;
}
Long num1 = long. Parse (args [0]);
Long num2 = long. Parse (args [1]);
SwapClass. Swap (ref num1, ref num2 );
// Note that the using command at the beginning of the file enables you to reference the DLL method using an undefined class name during compilation.
Console. WriteLine ("The result of swap is num1 = {0} and num2 = {1}", num1, num2 );
Long maxcd = MaxCDClass. MaxCD (num1, num2 );
Console. WriteLine ("The MaxCD of {0} and {1} is {2}", num1, num2, maxcd );
}
}

To generate an executable file MyClient.exe, use the following command line:

Csc/out: MyClient.exe/reference: MyLibrary. DLL MyClient. cs

The/out compiler option notifies the compiler to output the EXE file and specify the output file name (MyClient.exe ). The/reference compiler option specifies the DLL file referenced by the program.
To run the program, enter the name of the EXE file, followed by two numbers. For example:

MyClient 123 456

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.