how to use string and Console.ReadLine to enter multiple inputs? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

how to use string and Console.ReadLine to enter multiple inputs?

19th Jul 2016, 10:58 AM
某某人
某某人 - avatar
3 Answers
+ 1
When i make advanced consoles, i usually make a method that returns a string, like: // The 'msg' parameter is not needed, it only allows you to quickly make the difference of: //hi this is input // And: //> hi this is input if i typed "> " in the parameter. private static string GetInput(string msg = "") { Console.Write(msg); return Console.ReadLine(); } And i call it in the main like: public static void Main(string[] args) { string cmd = GetInput("> "); Console.WriteLine(cmd); cmd = GetInput(); Console.WriteLine(cmd); } Good luck!
19th Jul 2016, 2:39 PM
Luke Wilson
Luke Wilson - avatar
0
A suggestion would be to maybe use a for loop that includes a string variable that takes in Console.ReadLine() depending on the condition number.
19th Jul 2016, 1:48 PM
Jan Gundersen
Jan Gundersen - avatar
0
Example of my suggestion below: class Program { static void Main(string[] args) { for(int i=1; i<6; i++) { Console.Write(i + " " + "Write a name"); string strVar = Console.ReadLine(); Console.WriteLine(strVar); } } }
19th Jul 2016, 3:34 PM
Jan Gundersen
Jan Gundersen - avatar