0
Problem with ReadLine
I want to have a program that first shows a message telling enter your name. If name is ... then shows another message. But in mine does nt ask enter your name first. Both messages are shown at the end. Whats wrong ?
6 Antworten
+ 1
It looks fine to me. Except if you run this on code playground. Because in code playground the input is handled before the code is executed.
+ 3
It is also recommended to compare strings content using `Equals()` method rather than `==` operator.
if( a.Equals( "Morteza" ) )
+ 2
Here's a quick read to help understand
https://www.c-sharpcorner.com/UploadFile/3d39b4/difference-between-operator-and-equals-method-in-C-Sharp/
+ 1
Yes. I played it in code playground. I will try it in another compiler. Thanks.
+ 1
I am new to C# . I dont know how to use Equals() . What is the difference?
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Write your name");
string a = Console.ReadLine();
if ( a == "Morteza") {
Console.Write ("Welcome");
}
}
}
}