(C#) How to make commands with user input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

(C#) How to make commands with user input

What I mean is, how do you like type in the console, "cmds" and it will return with a lost of commands and let you talk again instead of just saying "Press any key to continue..." By the way im making an exploit for roblox if you were wondering.

20th Dec 2017, 1:27 PM
Aerial
Aerial - avatar
12 Answers
+ 1
I don`t understand your question but i think you want an infinite loop that reads from your keyboard: while (true) { string myString = Console.ReadLine(); Console.WriteLine(
quot;You typed: {myString}"); }
20th Dec 2017, 8:42 PM
Catalin Popinciuc
Catalin Popinciuc - avatar
+ 1
oh on sololearn ? you can't
21st Dec 2017, 8:37 PM
Catalin Popinciuc
Catalin Popinciuc - avatar
+ 1
well, you put 2 or more console.readline. example Console.ReadLine(); Console.ReadLine(); etc...
21st Dec 2017, 8:42 PM
Catalin Popinciuc
Catalin Popinciuc - avatar
+ 1
in visual studio u need an Console.Read() or an Console.ReadKey() at the end of your code in Main function because if you don't have that console.read() the application will exit without showing what you typed. it is like a 'return 0' in c/c++ . you can try my code from above with the infinite loop, that code will never quit. if you put something else after that while, that code will be unreachble and unused.
21st Dec 2017, 8:49 PM
Catalin Popinciuc
Catalin Popinciuc - avatar
+ 1
public static void Main(string[] args) { Console.ReadLine(); // reads until you press enter Console.ReadLine(); // reads until you press enter Console.ReadKey(); // press enter or press any button, the application will end. }
21st Dec 2017, 8:54 PM
Catalin Popinciuc
Catalin Popinciuc - avatar
+ 1
@Aerial , if the public static void Main(string[] args){ } is empty, the console will pop up and close imidiatly because nothing is going no there. Imagine that your Console.ReadLine() or .ReadKey() is the last piece of your code, task or something else to do for your app. After that the application ends. This is the way it works. Please try this: public static void Main(string[] args){ // this while iteration should be in the Main function of your application while (true) { string myString = Console.ReadLine(); Console.WriteLine(
quot;You typed: {myString}"); } // end of while iteration // if you write something else after this, you got a warning about "not reachable". } And you will see that your command line will never close, only if you want.
21st Dec 2017, 9:09 PM
Catalin Popinciuc
Catalin Popinciuc - avatar
0
just put a user input into an infinite loop
20th Dec 2017, 1:42 PM
Jeremy
Jeremy - avatar
0
I haven't covered loops yet but I will go check them out
20th Dec 2017, 1:44 PM
Aerial
Aerial - avatar
0
What I mean is, how do you type in the console and still be able to type after you have typed something
21st Dec 2017, 8:33 PM
Aerial
Aerial - avatar
0
no not on sololearn, on visual studio
21st Dec 2017, 8:38 PM
Aerial
Aerial - avatar
0
I tried that
21st Dec 2017, 8:43 PM
Aerial
Aerial - avatar
0
but I don't want it to end when I press enter, I want it to end whenever you close the console I want it in an infinite loop of Console.ReadLine();
21st Dec 2017, 8:56 PM
Aerial
Aerial - avatar