我的目標是通過myDictionary
從function1
到function2
並從function2
打印出來。我是一個新手,所以很有可能我的語法或格式不正確。將字典從一種功能傳遞到另一種功能並打印出來
// This is my main program
class Program
{
static void Main(string[] args)
{
function1();
}
}
// Create myDictionary in this function and then pass it to function2
static public void function1()
{
Dictionary<string, string> myDictionary = new Dictionary<string, string>();
myDictionary.Add("FirstName", "John");
myDictionary.Add("LastName", "Walter");
// passing myDictionary to another function
function2(myDictionary);
}
// Passing myDictionary to this function
static public function2(myDictionary<string, string>)
{
// print myDictionary from here
}
那麼,有什麼是你問的具體問題?它不編譯?或者你正在試圖找到合適的打印方法? –