• 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

  • 相关阅读:
    面试容易问到的Linux问题
    Java面试题复习笔记(框架)
    Java面试题复习笔记(前端)
    Java面试题复习笔记(数据库)
    Java面试题复习笔记(Web方向)
    【刷题-LeetCode】191 Number of 1 Bits
    【数学】随机方法计算逆矩阵
    【刷题-LeetCode】190 Reverse Bits
    【刷题-LeetCode】188 Best Time to Buy and Sell Stock IV
    python 30 面向对象之 多态
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/1383119.html
Copyright © 2020-2023  润新知