基础问题大家帮忙啊
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string f = "4 ";
string dd;
switch (f)
{
case( "2 "):
dd = "ffasdad ";
return;
case ( "4 "):
dd = "111111111 ";
return ;
}
Console.WriteLine( "{0} ", dd);
Console.ReadKey();
}
}
}
我的程序总是说我使用了未赋值的变量dd
谁能告诉我在case处怎么赋值啊,我是要在那里赋值,而不是打印
------解决方案--------------------string dd= " ";
------解决方案--------------------namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string f = "4 ";
string dd = null;
switch (f)
{
case "2 ":
dd = "ffasdad ";
break;
case "4 ":
dd = "111111111 ";
break;
default:
dd = null;
break;
}
Console.WriteLine( "{0} ", dd);
Console.ReadKey();
}
}
}
------解决方案--------------------string f = "4 ";
string dd = String.Empty ;
switch (f)
{