How to stop program executing further in C#

c#

Solution

I think you want to have a non empty string value as an input from console and if input is empty then want to terminate your application. Use following code:

Console.WriteLine("Enter a value: ");
string str = Console.ReadLine();
//If pressed enter here without a  value or data, how to stop the  program here without
//further execution??
if (string.IsNullOrWhiteSpace(str))
  return;
else
{
  Console.WriteLine(string.Format("you have entered: '{0}'", str));
  Console.Read();
}

If user will enter any kind of empty string or white spaces, the application will be terminated the moment he/she will press enter.

Problem

``` string FirstName = Console.ReadLine(); if (FirstName.Length > 12) { Console.WriteLine("......................................."); } if(FirstName.Length<3) { Console.WriteLine("...................."); } Console.WriteLine("..................."); string SecondName = Console.ReadLine(); if (SecondName.Length > 12) { Console.WriteLine("............................."); } if(SecondName.Length<3) { ``` I want to stop the program if they press enter without putting a value,how to do it??/?

Original source

Related problems