close

image

新增專案如下, 接著將Class1.cs重新命名為Add.cs

image

重新命名成Add.cs, Class1會自動更新成Add

image

Add.cs

命名空間:MyMethods

定義AddClass, 並包含一個靜態函式Add

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Text;
   4:  
   5: namespace MyMethods
   6: {
   7:     public class AddClass
   8:     {
   9:         public static long Add(long i, long j)
  10:         {
  11:             return (i + j);
  12:         }
  13:     }
  14: }

加入Mult.cs

image

選擇<類別>並輸入名稱Mult.cs

image

Mult.cs

命名空間:MyMethods

定義MultipyClass, 並包含一個靜態函式Multiply

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Text;
   4:  
   5: namespace MyMethods
   6: {
   7:     public class MultiplyClass
   8:     {
   9:         public static long Multiply(long x, long y)
  10:         {
  11:             return (x * y);
  12:         }
  13:     }
  14: }

編譯成功後會跳出一個對話框, 不用緊張只是提示: 類別庫是要給其他專案呼叫使用,無法直接執行!

image

產生動態函式庫 MyLibrary

image

--------------------------------------------------------------------------------------------------------------------------------------------

撰寫一個Console程式, 加入參考MyLibrary函式庫

image

選擇<主控台應用程式>

名稱: CallMyLibrary

image

加入參考

image

加入參考 C:\CSharp\MyLibrary\MyLibrary\bin\Release\MyLibrary.dll

image

滑鼠雙擊MyLibrary展開樹狀結構

image

設定起始專案並編譯

image

編譯器會自動複製動態函式庫MyLibrary.dll

image

在cmd命令輸入指令

> CallMyLibrary 2 5

image

 

 

參考資料: Microsoft 建立和使用 C# 的 DLL

範例程式: Download

全站熱搜
創作者介紹
創作者 me1237guy 的頭像
me1237guy

天天向上

me1237guy 發表在 痞客邦 留言(0) 人氣()