2014-03-31 76 views
0

我有一個測試項目,它是一個庫。我想編寫一個控制檯應用程序,以便能夠引用測試項目的DLL並從我的測試項目中調用方法和類。C#針對測試項目的可執行項目(控制檯應用程序)

此外,在編寫控制檯應用程序時,我想要如何使用參數從命令提示符執行exe。我的控制檯應用程序代碼應該接受我提供並執行測試的輸入。

我只需要一些示例代碼,以便我可以從那裏拿起它。

回答

0

你必須遵循以下步驟:

  1. 添加您的DLL文件作爲參考您的控制檯項目。 項目>>添加參考>>瀏覽並選擇你的dll文件。
  2. add usign myNamespaceOfMyDll;
  3. 然後在你的代碼中,你可以使用你的dll文件中的方法。

樣品(使用GMmap的DLL):

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using GMap.NET; 
usign myNamespace; 
namespace ConsoleApplication6 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
     //GPoint is a user data type declared in GMap.NET 
     //method is a method definied in myNamespace (your dll) 
     GPoint s=method(param1,param2); 
     } 
    } 
} 

假設你有一個代碼,你必須在你的主要方法中添加一個字符串數組作爲PARAM。

using System; 
class Program 
{ 
    static void Main(string[] args) 
    { 
if (args == null) 
{ 
    Console.WriteLine("args is null"); // Check for null array 
} 
else 
{ 
    //Here you can to use then content of your args array. 
} 
Console.ReadLine(); 
    } 
} 

因此如果鍵入:

c:\> myApp param1 param2 

ARGS [0] = 「參數1」,ARGS [1] = 「參數2」,並且陣列的長度是2。

+0

謝謝你非常感謝萊昂內爾。你能回答這個問題的第二部分嗎? 「另外,在編寫控制檯應用程序時,我想要如何使用參數從命令提示符執行exe。我的控制檯應用程序代碼應該接受輸入並執行測試。」 – Sanmathi

相關問題