Creating
an if/else statement in C# is easy. However,
when you are a beginner it’s a bit difficult.
I learned this simple program while learning through Microsoft C#
programming courses. It’s short and
clean and provides the basic concepts.
I
admit when I first learned the if/else statements I got a little creative. It’s almost like a game. You could make it go on forever and ever if
you want to.
I
recommend the programming in C# classes at Microsoft. It was a free course I found by accident
online on their website.
Here's the source code:
Using IF/Else Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IfElse
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hey, pick a
number from 1 through 3");
string userValue = Console.ReadLine();
string message = "";
if (userValue == "1")
{
message = "You won a trip to Bahamas!";
}
else if (userValue == "2")
message = "You win $200!";
else if (userValue == "3")
message = "You win dinner for two at Outback Steakhouse!";
else
message = "Sorry, we didn't understand. You are a loser!";
Console.WriteLine(message);
Console.ReadLine();
}
}
}
No comments:
Post a Comment