C# csc构建dll 和 csc构建时指定dll

文章描述了一位开发者在创建和使用C#DLL时遇到的问题。他们首先创建了一个名为mydll的DLL,包含一个公共类MyMath,提供加法和减法方法。然后在testdll项目中尝试引用mydll,初时遇到错误。通过使用/r编译选项正确指定DLL引用后,成功构建并运行了testdll,实现了对mydll中方法的调用。
摘要由CSDN通过智能技术生成

新建一个mydll.cs;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace myDLL
{
    public class MyMath
    {
        public int add(int x, int y)
        {
            return x + y;
        }

        public int sub(int x, int y)
        {
            return x - y;
        }
    }
}

用下图命令构建为dll;看下dll有了; 

新建一个testdll.cs;

using System;
using myDLL;

class Program
{

static void Main(string[] args)
{
    MyMath a = new MyMath();
    int c = a.add(99, 77);
    Console.WriteLine("99+77=" + c);

    Console.ReadKey();
}

}

目前都是在同一目录;构建testdll.cs;出错; 

 

看一下指定需要的dll是不是 /addmodule ,错了,

 

用 /r 指定需要的dll,然后构建;构建成功,运行如下;

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值