我正在对着墙壁狠狠地敲打着我的头。我在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