How to process input from Console.Readline C#

[By JayDev64x] [Index]

It is important to know how to process text from a Console.Readline to make a functioning console-based application. In C#, all you have to do is declare it as a variable, which in this case it is best to define as a string. In return, you can use this new variable in an if statement to check if it matches any words you want to have it respond to.

using System; namespace Script { class Example { static void Main() { Console.WriteLine("yes or no"); // Defines the input as a string. string answer = Console.ReadLine(); if (answer == "yes") { // Do something. } if (answer == "no") { // Do something. } } } }

Created [September 1, 2021]