User Input in Windows Console Application – C#


 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InputTest
{
class Program
{
static void Main(string[] args)
{
System.Console.Write("SOFTWARE TERMS OF USE\nYou can use the SoftwareSamples from Chas for free, for demonstration purposes or to help you with your coding, including for business or professional use. You do not have to give credit to Chas AT ALL, though it would be appreciated.\n");
System.Console.WriteLine("Do you accept the Terms of this software?");
String agree = System.Console.ReadLine();
if (agree == "yes")
{
System.Console.WriteLine("Terms accepted. You may use this software");
}
if (agree == "YES")
{
System.Console.WriteLine("Terms accepted. You may use this software");
}
if (agree == "Y")
{
System.Console.WriteLine("Terms accepted. You may use this software");
}
if (agree == "y")
{
System.Console.WriteLine("Terms accepted. You may use this software");
}
if (agree == "n")
{
System.Console.WriteLine("You did not accept the terms. You may not use this software.");
}
if (agree == "no")
{
System.Console.WriteLine("You did not accept the terms. You may not use this software.");
}
if (agree == "NO")
{
System.Console.WriteLine("You did not accept the terms. You may not use this software.");
}
if (agree == "N")
{
System.Console.WriteLine("You did not accept the terms. You may not use this software.");
}
}
}
}

Hi guys, here is how to use input in a Windows Console Application. In this sample, the user has to type YES, yes, Y or y to get access to the software, and if they type NO, no, N or n they will not get access to the software. There is no “software” that will be installed in this script. This is only for demonstration purposes.

Go on, you know you want to! Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: