错误2使用未分配的局部变量的“Y” [英] Error 2 Use of unassigned local variable 'Y'

查看:228
本文介绍了错误2使用未分配的局部变量的“Y”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我又碰到一个错误我的意思不是错误的人,但我对这个code得到一个错误:

Again i run into an error i don't mean to bug anyone but I'm getting an error on this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Input_Program
{
    class Program
    {
       private static void Main()
        {

           char Y;
            char N;

           Console.WriteLine("Welcome to my bool program!");
           Console.WriteLine("Input a NON capital y or n when told to.");




            if(Y == 'y')
            {
                Console.WriteLine("Thank you,Please wait.....");
            }
        }
    }
}

感谢您的解答!

Thanks for you answers!

推荐答案

您变量字符是使用前未初始化。尽量给声明时的默认值。

Your variable char Y is not initialized before using. Try to give a default value when declaring.

修改看来你希望用户输入的东西,并把它分配给变量Y的尝试:

EDIT It seems that you want the users to input something, and assign it to the variable Y. Try:

Y = Console.ReadKey().KeyChar;

这篇关于错误2使用未分配的局部变量的“Y”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆