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;
            }
        }

    }
}
相关推荐
晨星shine2 天前
GC、Dispose、Unmanaged Resource 和 Managed Resource
后端·c#
用户298698530142 天前
.NET 文档自动化:Spire.Doc 设置奇偶页页眉/页脚的最佳实践
后端·c#·.net
用户3667462526742 天前
接口文档汇总 - 2.设备状态管理
c#
用户3667462526742 天前
接口文档汇总 - 3.PLC通信管理
c#
Ray Liang3 天前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
Scout-leaf6 天前
WPF新手村教程(三)—— 路由事件
c#·wpf
用户298698530146 天前
程序员效率工具:Spire.Doc如何助你一键搞定Word表格排版
后端·c#·.net
mudtools7 天前
搭建一套.net下能落地的飞书考勤系统
后端·c#·.net
玩泥巴的7 天前
搭建一套.net下能落地的飞书考勤系统
c#·.net·二次开发·飞书
唐宋元明清21887 天前
.NET 本地Db数据库-技术方案选型
windows·c#