My son was trying his hands on codes writings to a lttle windows application, the he realised he would like to set a condition as to how many characters or a limitation on the leght of string input from the user, cos without a limitation the user might write a long lenghty name , and so on.
can anyone help os with how to write an example of set conditions to inputs from the user.

e.g. if we write(this is just a pseaudo code)

Console.Writeline (" Player enter your name and press enter");
String name = Console.ReadLine();

if name...........
&& string.Lenght ...........
accept
else
throw exception.
hope there will be some help.

Just do
if ( name.Length > 30
{
Console.WriteLine("name too long");
}

okay, thanks for saving me, my son is now glad . thanks ddanbee

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.