C#_库的引用


类库的引用

还可以自己引用类库:解决方案-添加-新建项目

主程序

bash 复制代码
using System;
using System.Windows.Forms;
using Tools;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("helloword");
            // Form form = new Form();
            // form.ShowDialog();
            double result = Calculator.Mul(3, 4);
            Console.WriteLine(result);
        }
    }
}

在引用里添加自己创建的类库

类库程序

bash 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace Tools
{
    public class Calculator
    {
        public static double Add(double a, double b)
        {
            return a + b;
        }
        public static double Sub(double a, double b)
        {
            return a - b;
        }
        public static double Mul (double a, double b)
        {
            return a * b;
        }
        public static double Div(double a, double b)
        {
            if (b == 0)
            {
                return double.PositiveInfinity;
            }
            else
            {
                return a / b;
            }
        }

    }
}
相关推荐
014-code5 小时前
订单超时取消与库存回滚的完整实现(延迟任务 + 状态机)
java·开发语言
lly2024065 小时前
组合模式(Composite Pattern)
开发语言
游乐码6 小时前
c#泛型约束
开发语言·c#
Dontla6 小时前
go语言Windows安装教程(安装go安装Golang安装)(GOPATH、Go Modules)
开发语言·windows·golang
chushiyunen6 小时前
python rest请求、requests
开发语言·python
铁东博客6 小时前
Go实现周易大衍筮法三变取爻
开发语言·后端·golang
baidu_huihui6 小时前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip
南 阳6 小时前
Python从入门到精通day63
开发语言·python
lbb 小魔仙6 小时前
Python_RAG知识库问答系统实战指南
开发语言·python
hoiii1876 小时前
C# 基于 LumiSoft 实现 SIP 客户端方案
前端·c#