C#为什么会说我使用了“未赋值的局部变量d”
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespa...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
delegate double mydelegate(double a, double b);
static double chen(double a, double b)
{
return a * b;
}
static double chu(double a, double b)
{
return a / b;
}
static double jia(double a, double b)
{
return a + b;
}
static void Main(string[] args)
{
mydelegate d;
Console.WriteLine("输入两个数字:");
double a = Convert.ToDouble(Console.ReadLine());
double b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入运算符");
string h=Console.ReadLine();
if(h=="*")
d=new mydelegate(chen);
else if(h=="/")
d=new mydelegate(chu);
Console.WriteLine("result:{0}",d(a,b) );
Console.ReadKey();
}
}
} 展开
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
delegate double mydelegate(double a, double b);
static double chen(double a, double b)
{
return a * b;
}
static double chu(double a, double b)
{
return a / b;
}
static double jia(double a, double b)
{
return a + b;
}
static void Main(string[] args)
{
mydelegate d;
Console.WriteLine("输入两个数字:");
double a = Convert.ToDouble(Console.ReadLine());
double b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("请输入运算符");
string h=Console.ReadLine();
if(h=="*")
d=new mydelegate(chen);
else if(h=="/")
d=new mydelegate(chu);
Console.WriteLine("result:{0}",d(a,b) );
Console.ReadKey();
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询