vs2019白盒引用(类)

1.解决方案资源管理器,右键点击解决方案--添加--新建项目(现有项目)

必须是class library项目

 

 2.可以看到已经添加的项目 person

在Class1.cs里面我们简单的写一些代码:

using Microsoft.Analytics.Interfaces;
using Microsoft.Analytics.Interfaces.Streaming;
using Microsoft.Analytics.Types.Sql;
using System;
using System.Collections.Generic;


namespace person
{
    public class P
    {
        public int age;
        public double score;
        public string sex;
        public static double Ad(int a,int b)
        {
            return a + b;
        }
        public static double Sub(int a, int b)
        {
            return a - b;
        }
    }
}

 

3.右键依赖项--添加项目引用

 

4.可以看到已经添加的person,打勾--确定。

5.可以看到hello项目就引入了person项目了

6.我们在hello.cs里面写一些代码:一定要using person; 才可以

using System;
using System.Collections;
using System.Collections.Generic;
using person;//引用项目person

namespace hello
{
    class hello
    {
        static void Main(string[] args)
        {
            double sum=P.Ad(1, 2);//使用 P 里面的方法Add
            Console.WriteLine(sum);

            P p1 = new P//实例化类P
            {
                age = 10,
                sex = "女"
            };
            p1.score = 90.99;
            //list这样
            List<P> p2 = new List<P>();
            p2.Add(p1);
            p1.age = 12;
            p1.sex = "男";
            //或者这样
            List<P> p3 = new List<P>();
            p3.Add(new P
            {
                age = 13,
                sex="男"
            }) ;   
            Console.WriteLine(p1.sex);//12
            p2.Remove(p1);
        }
    }
}

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十年人间~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值