我正在對着牆壁狠狠地敲打着我的頭。我在C#控制檯應用程序中有幾個我想要重用的變量。但是,我不能在我的生活中重新使用另一個班的變量。我很樂意提供任何幫助或指引 - 我已經搜索了很長時間,而且我完全陷入了困境。將變量從Main函數傳遞到另一個C#類
編輯:是的,變量是我的主要功能。對不起,這個離開了。
編輯:下面沉重的編輯代碼。我想在其他課程中重用的變量值在中間。還有更多,但這3個應該足夠樣本。感謝您的幫助!
public static class MyApp
{
static void Main(string[] args)
{
// loads XML doc
foreach (XmlNode node in nodes)
{
try
{
// does a bunch of stuff
// Parses variables from REST API
XDocument docdetailxml = XDocument.Parse(xmldoc);
XNamespace ns = docdetailxml.Root.GetDefaultNamespace();
var buid = docdetailxml.Root.Element(ns + "busid").Value;
var bname = docdetailxml.Root.Element(ns + "busname").Value;
var bcount = docdetailxml.Root.Element(ns + "buscount").Value;
// Invoke SQL connection string
// Trigger Stored Procedure and write values to database
// If needed, trigger email notification
// Close connections
}
catch (Exception e)
{
Console.WriteLine("Error encountered: " + e.Message);
// Exit the application
System.Environment.Exit(1);
}
finally
{
// Exit the application
// System.Environment.Exit(0);
}
}
}
private static void GetConnectionString()
{
throw new NotImplementedException();
}
private static void GetConnectionStrings()
{
throw new NotImplementedException();
}
}
}
你是指傳遞給你的'Main'函數的'string [] args'嗎?你能顯示迄今爲止製作的代碼嗎? – Default 2012-01-03 07:53:49
你有代碼示例來顯示出現問題嗎?這會幫助我們一點。 – 2012-01-03 07:53:57
請發佈您的控制檯應用程序的代碼。 – 2012-01-03 07:53:57