ASP.NET(C#)生成DLL

我们创建以下C#代码文件:
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运行:csc /target:library /out:MyDLL.DLL MySwap.cs MyMaxCD.cs完成后可在本目录下面找到我们刚才生成的MyDLL.DLL文件/target:library 编译器选项通知编译器输出 DLL 文件而不是 EXE 文件。后跟文件名的 /out 编译器选项用于指定 DLL 文件名。如果/out后面不跟文件名编译器使用第一个文件 (MySwap.cs) 作为 DLL 文件名。生成的文件为MySwap.DLL文件。

建立:MyClient.cs 文件:
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);
// 请注意,文件开头的 using 指令使您得以在编译时使用未限定的类名来引用 DLL 方法
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);
}
}


若要生成可执行文件 MyClient.exe,请使用以下命令行:

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

/out 编译器选项通知编译器输出 EXE 文件并且指定输出文件名 (MyClient.exe)。/reference 编译器选项指定该程序所引用的 DLL 文件。
若要运行程序,请输入 EXE 文件的名称,文件名的后面跟两个数字,例如:

MyClient 123 456

转载于:https://www.cnblogs.com/chenbg2001/archive/2009/02/03/1383119.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值