C#中創建和使用dll

 

C#中創建和使用dll比c++中方便多了!C#中沒有了C++中的.h頭文件,確實省了很多麻煩。

創建一個dll

using System;
using System.Collections.Generic;
using System.Text;

namespace ClassLibrary1
{
public class AddClass
{
public static long add(long a, long b)
{
return (a + b);
}
}
}

非常簡單地就創建了一個dll,提供add函數

 

使用也非常簡單:

using System;
using System.Collections.Generic;
using System.Text;
using ClassLibrary1;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Calling DLL library 000000000000000");

long num = AddClass.add(5, 6);

Console.WriteLine("The sum of 5 and 6 is: {0}", num);
}
}
}

就相當於使用一個命名空間中的一個類中的一個函數。當然了,要把dll加到reference中去的。Project->Add Reference->Browse->然後選擇你要加入的dll即可。灰常灰常簡單。記得要把名字空間加進來。 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章