c sharp dll

1. generate dll

building .cs file, for example: myDll.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DZTT
{
    public class Operate
    {
        public int getSum(int a, int b)
        {
            return a + b;
        }
    }
}
View Code

enter vs menu->cmd

csc /target:library /out:myDll.DLL myDll.cs

2. building console project testDll

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using DZTT; 
namespace TestDll 
{ 
class Program 
{ 
static void Main(string[] args) 
{ 
Operate operate = new Operate(); 
int c = operate.getSum(10 ,20); 
Console.WriteLine(c.ToString()); 
} 
} 
} 
View Code

3. Project->Add reference, add myDll.dll

ok.

猜你喜欢

转载自www.cnblogs.com/https/p/9642884.html
今日推荐