主题:有个问题想请教高手
本人初学C#,随便写个程序有问题
请教各位高手
using System;
class exercise
{
public static void Main()
{
//string input1;
char ch;
string input1=Console.ReadLine();
for(int i=0;i<input1.Length;i++)
{
if (i==0)
{
ch=input1[input1.Length-1];
}
if (i!=0)
{
if (input1[i-1]<'x')
{
ch=(char)((int)input1[i-1]+3);
}
else
{
switch (input1[i-1])
{
case 'x': ch='a'; break;
case 'y': ch='b'; break;
case 'z': ch='c'; break;
default : break;
}
}
}
Console.Write(ch);
}
//Console.WriteLine(input1.Length);
Console.ReadLine();
}
}
错误是:use of unassigned local variable 'ch'
请教各位高手
using System;
class exercise
{
public static void Main()
{
//string input1;
char ch;
string input1=Console.ReadLine();
for(int i=0;i<input1.Length;i++)
{
if (i==0)
{
ch=input1[input1.Length-1];
}
if (i!=0)
{
if (input1[i-1]<'x')
{
ch=(char)((int)input1[i-1]+3);
}
else
{
switch (input1[i-1])
{
case 'x': ch='a'; break;
case 'y': ch='b'; break;
case 'z': ch='c'; break;
default : break;
}
}
}
Console.Write(ch);
}
//Console.WriteLine(input1.Length);
Console.ReadLine();
}
}
错误是:use of unassigned local variable 'ch'