【发布时间】:2012-09-24 19:39:21
【问题描述】:
我查看了 google 和其他 stackoverflow Use of unassigned local variable 错误,但仍然找不到答案。我认为也许我的错误是因为滥用了 ExtractionCtrl 的范围。我尝试了这段代码来测试范围并且它有效。所以我现在不知道我的错误在哪里。
测试范围
namespace RandomTesting
{
internal class Program
{
private static void Main(string[] args)
{
int x = 5;
switch (x)
{
case 2:
System.Console.WriteLine("Your # is 2");
break;
case 5:
System.Console.WriteLine("Your # is :{0}", x);
x = x + 2;
System.Console.WriteLine("Your # is :{0}", x);
break;
}
System.Console.WriteLine("Your # is :{0}", x);
Console.ReadLine();
}
}
}
部分主要代码
switch (arg)
{
case "AR":
ExtractionCtrl = new ARExtractionController();
// add new mapping here
break;
case "ICN":
ExtractionCtrl = new IcnExtractionController();
// add new mapping here
break;
}
int ticketID;
if (int.TryParse(arg, out ticketID))
{
string returnedFilePath = ExtractionController.GetStartupPath();
ExtractionCtrl.Extract(ticketID, returnedFilePath, AR_TEMPLATE_PATH, MAPPING_PATH);
}
【问题讨论】:
-
arg的值实际上是“AR”还是“ICN”?注意区分大小写。 -
你在哪里得到错误?如果是因为
ExtractionCtrl未分配,那么请发布代码,说明它的定义位置和赋值位置 -
如果arg的值是AR或者ICN,你为什么要做int.TryParse?不会总是假的吧?
-
-arg is "AR" - int.Tryparse : 我知道,对不起,我正在尝试修改别人的代码