C# 给出一个错误,表示未分配局部变量
这是我为解决一个数学问题而编写的一个简单代码C# 给出一个错误,表示未分配局部变量,c#,variables,C#,Variables,这是我为解决一个数学问题而编写的一个简单代码 namespace StoreCredit { class Program { private static int No1; static void Main(string[] args) { string[] text = System.IO.File.ReadAllLines(@"input.txt"); int nocases =
namespace StoreCredit
{
class Program
{
private static int No1;
static void Main(string[] args)
{
string[] text = System.IO.File.ReadAllLines(@"input.txt");
int nocases = int.Parse(text[0]);
int J = 1;
int No1=0;
int No2=0;
for (int x = 1; x <= nocases;x++ )
{
int Amount = int.Parse(text[J]);
int NoItem = int.Parse(text[J+1]);
char[] delimiterChars = { ' ' };
string[] Values = text[J+2].Split(delimiterChars);
int z = 0;
bool found = false;
while ((z < NoItem) && !found)
{
int Item = int.Parse(Values[z]);
int Remaining = Amount - Item;
int y = 0; bool found2 = false;
while ((y < NoItem) && !found2)
{
if (Remaining == int.Parse(Values[y])&&!(y==z))
{
Console.WriteLine("Found a match");
found = true;
found2 = true;
Console.WriteLine("Value 1 = {0} and Value 2={1}",(z+1),(y+1));
}
y++;
}
z++;
}
string lines = "Case #" + x + ": ", z, y;
StreamWriter file2 = new StreamWriter(@"output.txt", true);
file2.WriteLine(lines);
file2.Close();
J = J + 3;
}
}
}
}
名称空间存储信用
{
班级计划
{
专用静态int 1号;
静态void Main(字符串[]参数)
{
字符串[]text=System.IO.File.ReadAllLines(@“input.txt”);
int nocases=int.Parse(文本[0]);
int J=1;
int No1=0;
int No2=0;
对于(int x=1;x靠近末尾的这一行尝试重新声明z
和y
,因为它们之间用逗号分隔:
string lines = "Case #" + x + ": ", z, y;
您是否打算将它们连接起来?例如:
string lines = "Case #" + x + ": " + z + y; // notice the + instead of comma