Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 名为';结果';无法在此作用域中声明(错误CS0136)_C# - Fatal编程技术网

C# 名为';结果';无法在此作用域中声明(错误CS0136)

C# 名为';结果';无法在此作用域中声明(错误CS0136),c#,C#,我正在学习c#,我正在尝试制作一个程序来计算(lol)传奇联盟的冠军胜率,我被这个问题困扰着: 错误是: 错误CS0136无法在中声明名为“Result”的本地或参数 此范围无效,因为该名称在封闭的本地范围中用于 定义局部或局部参数 这是我的密码: namespace ConsoleApp4 { class Program { static void Main(string[] args) { double TeemoWi

我正在学习c#,我正在尝试制作一个程序来计算(lol)传奇联盟的冠军胜率,我被这个问题困扰着:

错误是:

错误CS0136无法在中声明名为“Result”的本地或参数 此范围无效,因为该名称在封闭的本地范围中用于 定义局部或局部参数

这是我的密码:

namespace ConsoleApp4
{
    class Program
    {

        static void Main(string[] args)
        {
            double TeemoWinRate = 51.33;
            double AkaliWinRate = 47.56;
            double YasuoWinRate = 49.73;
            double KhazixWinRate = 50.94;
            double YoneWinRate = 47.84;
            double LuxWinRate = 50.50;
            double MorgWinRater = 50.83;
            double TrandyWinRate = 48.50;
            double GarenWinRate = 50.50;

            double TeemoGold = 11.113;
            double AkaliGold = 10.880;
            double YasuoGold = 11.828;
            double KhazixGold = 11.541;
            double YoneGold = 11.650;
            double LuxGold = 9.497;
            double MorgGold = 8.990;
            double TrandyGold = 12.182;
            double GarenGold = 11.609;

            double Te = TeemoWinRate;
            double A = AkaliWinRate;
            double Y = YasuoWinRate;
            double K = KhazixWinRate;
            double Yo = YoneWinRate;
            double L = LuxWinRate;
            double M = MorgWinRater;
            double Tr = TrandyWinRate;
            double G = GarenWinRate;



            Console.WriteLine("Champions Ranked WinRate From the list below");
            Console.WriteLine("Akali, " +
                "Yasuo, " +
                "Khazix, " +
                "Yone, " +
                "Lux, " +
                "Morg, " +
                "Trandy, " +
                "Garen, " +
                "Teemo.");
            Console.WriteLine("Note: get sure that names are written as the list");

            Console.Write("Enter Champion Name : ");

            string Champion = Console.ReadLine();
            
            //------------------------------First if stattement--------------------------------------------
            if (Champion == "Akali")
            {
                Console.WriteLine("Akali WinRate is: " + AkaliWinRate + " " + "Total Gold: " + AkaliGold);
            }
            else if (Champion == "Yasuo")
            {
                Console.WriteLine("Yasuo WinRate is: " + YasuoWinRate + " " + "Total Gold: " + YasuoGold);
            }
            else if (Champion == "Khazix")
            {
                Console.WriteLine("Khazix WinRate is: " + KhazixWinRate + " " + "Total Gold: " + KhazixGold);
            }
            else if (Champion == "Yone")
            {
                Console.WriteLine("Yone WinRate is: " + YoneWinRate + " " + "Total Gold: " + YoneGold);
            }
            else if (Champion == "Lux")
            {
                Console.WriteLine("Lux WinRate is: " + LuxWinRate + " " + "Total Gold: " + LuxGold);
            }
            else if (Champion == "Morg")
            {
                Console.WriteLine("Morg WinRate is:" + MorgWinRater + " " + "Total Gold: " + MorgGold);
            }
            else if (Champion == "Trandy")
            {
                Console.WriteLine("Trandy WinRate is: " + TrandyWinRate + " " + "Total Gold: " + TrandyGold);
            }
            else if (Champion == "Garen")
            {
                Console.WriteLine("Garen WinRate is: " + GarenWinRate + " " + "Total Gold: " + GarenGold);
            }
            else if (Champion == "Teemo")
            {
                Console.WriteLine("Teemo WinRate is" + TeemoWinRate + " " + "Total Gold: " + TeemoGold);
            }
            else
            {
                Console.WriteLine("Please Enter the name Exactly as in the list.");
                return;
            }
      

            Console.WriteLine("what champion do u want to Compare with other champs");
            Console.WriteLine("Type " +
                "\n 1 for (Teemo) " +
                "\n 2 for (Akali) " +
                "\n 3 for (Yasuo) " +
                "\n 4 for (khazix) " +
                "\n 5 for (Yone) " +
                "\n 6 for (Lux)" +
                "\n 7 for (Morg)" +
                "\n 8 for (Trandy)" +
                "\n 9 for (Garen)");
            Console.Write("First Champion: ");
            double Answer1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Second Champion");
            double Answer2 = Convert.ToInt32(Console.ReadLine());

            

            //------------------------------Second if stattement--------------------------------------------
            if (Answer1 == 1)
            {
                object Result = Answer1 - 1 + Te;
            }
            if (Answer1 == 2)
            {
                object Result = Answer1 - 2 + A;
            }
            if (Answer1 == 3)
            {
                object Result = Answer1 - 3 + Y;
            }
            if (Answer1 == 4)
            {
                object Result = Answer1 - 4 + K;
            }
            if (Answer1 == 5)
            {
                object Result = Answer1 - 5 + Yo;
            }
            if (Answer1 == 6)
            {
                object Result = Answer1 - 6 + L;
            }
            if (Answer1 == 7)
            {
                object Result = Answer1 - 7 + M;
            }
            if (Answer1 == 8)
            {
                object Result = Answer1 - 8 + Tr;
            }
            if (Answer1 == 9)
            {
                object Result = Answer1 - 9 + G;
            }
            //-----------------------------------Third if Statement--------------------------
            if (Answer2 == 1)
            {
                object Result2 = Answer2 - 1 + Te;
            }
            if (Answer2 == 2)
            {
                object Result2 = Answer2 - 2 + A;
            }
            if (Answer2 == 3)
            {
                object Result2 = Answer2 - 3 + Y;
            }
            if (Answer2 == 4)
            {
                object Result2 = Answer2 - 4 + K;
            }
            if (Answer2 == 5)
            {
                object Result2 = Answer2 - 5 + Yo;
            }
            if (Answer2 == 6)
            {
                object Result2 = Answer2 - 6 + L;
            }
            if (Answer2 == 7)
            {
                object Result2 = Answer2 - 7 + M;
            }
            if (Answer2 == 8)
            {
                object Result2 = Answer2 - 8 + Tr;
            }
            if (Answer2 == 9)
            {
                object Result2 = Answer2 - 9 + G;
            }
        }
    }
}

错误表明您无法使用
Result
,因为它正在其他地方使用。请尝试重命名它。

您不能多次定义
Result
。即使“您”知道只有一(1)条
if
语句将执行,编译器也不知道这一点,并假定代码可以输入
if
语句中的“任何或所有”。因此,编译器抱怨这个多重定义。在
if
语句
object Result=null之前定义变量
然后在下面的每个
if
语句中,删除
对象
定义…
Result=Answer1-1+Te。或者串一组
if/else
语句,或者使用
Case/Switch
语句。同样的想法也适用于<代码>结果2>代码>哦,我忘记了我可以在if语句之外声明它,并且使用它而不每次声明它,谢谢你先生。考虑改变所有的,但是第一个<代码>如果< /代码>(对于每个变量)到<代码>否则如果。还要问问自己——为什么要设置
Result2
,然后什么也不做呢?thx寻求帮助:)这个建议可以解决这个问题,但是,它不会提高作者的编码质量。每个
结果
都必须以不同的方式重命名,这将导致代码质量低下。