代码:using System;class hello
{
public static void Main()
{
string svb;
Console.WriteLine("yes or no?");
svb=Console.ReadLine();
if (svb == 'y')
{
Console.WriteLine("hello world!!");
}
Console.WriteLine("bye bye!!");
}
};出错提示:yon.cs(10,7): error CS0019: 运算符“==”无法应用于“string”和“char”类型的操作数这个例子我是直接抄袭的教材上的,怎么解决呢?

解决方案 »

  1.   

    'y'->"y"即可。using System;class hello
    {
    public static void Main()
    {
    string svb;
    Console.WriteLine("yes or no?");
    svb=Console.ReadLine();
    if (svb == "y")
    {
    Console.WriteLine("hello world!!");
    }
    Console.WriteLine("bye bye!!");
    }
    };
      

  2.   

    svb是字符串,你可以改写成
    using System;class hello
    {
    public static void Main()
    {
    string svb;
    Console.WriteLine("yes or no?");
    svb=Console.ReadLine();
    if (svb == "y")
    {
    Console.WriteLine("hello world!!");
    }
    Console.WriteLine("bye bye!!");
    }
    };