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