Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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# CS0165:使用未分配的局部变量'gender';_C# - Fatal编程技术网

C# CS0165:使用未分配的局部变量'gender';

C# CS0165:使用未分配的局部变量'gender';,c#,C#,我正在尝试创建一个脚本来计算男性和女性的BMR并显示结果。但我遇到了一个显示“error CS0165:Use of unassigned local variable`gender”的错误 using System; namespace CSE1101Unit2Lab { class MainClass { public static void Main (string[] args) { Console.Write (

我正在尝试创建一个脚本来计算男性和女性的BMR并显示结果。但我遇到了一个显示“error CS0165:Use of unassigned local variable`gender”的错误

using System;

namespace CSE1101Unit2Lab
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.Write ("Hello, what is your name?: ");
            string userName = Console.ReadLine ();
            Console.Write (" What is your age?: ") ;
            int age = int.Parse (Console.ReadLine ());
            Console.Write (" What is your weight in pounds?: ");
            int weight = int.Parse (Console.ReadLine ());
            Console.Write (" What is your height in inches?: ");
            int height = int.Parse (Console.ReadLine ());
            Console.Write (" What is your gender? Male or Female? (please type M = male and F = female): ");
            string gender;
            double genderFemale = double.Parse (Console.ReadLine ());
            double genderMale = double.Parse (Console.ReadLine ());




            Console.WriteLine (" Your age: " + age);
            Console.WriteLine (" Your weight: " + weight);
            Console.WriteLine (" Your height: " + height);
            Console.WriteLine (" Your gender: " + gender);


            if (gender == "F") 

            {
                genderFemale = 655 + (4.35 * weight) + (4.7 * height) - (4.7 * age);
            }
            else 

            {
                genderMale = 66 + (6.23 * weight) + (12.7 * height) - (6.8 * age);
            }
            int bmr = int.Parse (Console.ReadLine ());
            Console.WriteLine (" Your BMR is: " + bmr);





        }
    }
}

您声明了
性别
,但没有为其指定默认值,而且从未设置过

我想你应该改变这个

string gender;
对此

string gender = Console.ReadLine();

您从未分配过
性别
。阅读警告的内容。。。