08-09-2007, 14:50
|
|
|
|
חבר מתאריך: 01.05.06
הודעות: 7,861
|
|
בדיקת קלט ב C#
מה שאני רוצה לעשות זה בדיקת קלט, במידה והקלט = yes, תוצג הודעה.
הבעיה שמסיבה שלא ברורה לי אי אפשר להשתמש באופרטור == למחרוזות:
קוד:
using System;
public class MyProgram
{
public static void Main(string[] args)
{
Console.WriteLine("Would you like to try again?(yes,no)");
char answer = char.Parse(Console.ReadLine());
if (answer == "yes")
{
Console.Write("you choose 'yes'");
}
}
}
השגיאה המתקבלת:
קוד:
Error 1 Operator '==' cannot be applied to operands of type 'char' and 'string' C:\Documents and Settings\Netanel\My Documents\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 9 13 ConsoleApplication1
מדוע אי אפשר להשתמש בדרך זו (הידועה לי משפת PHP), ובאיזה דרך חלופית כן אפשר להשתמש?
|