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