I'm creating a Desktop application (console) for Windows, using C#.
This is my code:
namespace myapp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello!");
Console.WriteLine("Type 'exit' to exit!");
string line = Console.ReadLine();
if (line == "exit") {
Environment.Exit(0);
}
if (line == "copyright") {
Console.WriteLine("Copyright 2017 TIVJ-dev");
}
}
}
}
If I type "exit", it works fine (I'm sure it does this Environment.Exit(0);
action). But if I type "copyright", it does not work. I can see an empty line instead. I started with C# today, so my apologies if this is very beginner problem. I haven't found solution on the internet.
Screenshot:
You could use an else if statement;
Edit
By using an
if/else
this does the same as using multipleif
statements however this is a more efficient way and make it easier when using break points.