Problem with ReadLine | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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