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 ?

16th Dec 2020, 5:55 AM
Morteza Mohammadi
Morteza Mohammadi - avatar
6 odpowiedzi
+ 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.
16th Dec 2020, 6:06 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 3
It is also recommended to compare strings content using `Equals()` method rather than `==` operator. if( a.Equals( "Morteza" ) )
16th Dec 2020, 6:20 AM
Ipang
+ 1
Yes. I played it in code playground. I will try it in another compiler. Thanks.
16th Dec 2020, 6:12 AM
Morteza Mohammadi
Morteza Mohammadi - avatar
+ 1
I am new to C# . I dont know how to use Equals() . What is the difference?
16th Dec 2020, 6:21 AM
Morteza Mohammadi
Morteza Mohammadi - avatar
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"); } } } }
16th Dec 2020, 5:58 AM
Morteza Mohammadi
Morteza Mohammadi - avatar