c# 实现类库并调用


VS2012下实现类库,并调用。

 

1.创建类库

 

2.代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ClassLibrary
{
    public class Person
    {
        private string name;

        public Person(string name)
        {
            this.name = name;
        }

        public void sayHello()
        {
            Console.WriteLine("Hello Everyone!");
        }

    }
}

 

 

3.生成解决方案(Build),在项目的Debug\Bin下可以找到生成的.dll

 

4.新建控制台应用项目

 

 

4.引用添加ClassLibrary.dll

 

5. 测试代码如下:

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

namespace ClassLibraryTest
{
    class Program
    {
        static void Main(string[] args)
        {
            ClassLibrary.Person Jack = new ClassLibrary.Person("Jack");
            Jack.sayHello();

            Console.ReadKey();
        }
    }
}

 

6.运行成功:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM