How to use Swich-Case in C-sharp or C# ?
Hello Eveyone,
I will release some tutorial for beginners or independent learner in C# programming. I hope, these papers will help learner who like every time in their life.
Swich-case is a type selection on programming. there are also other programs like that C++, so it takes after if-else structure in C#. They are a main rule between conditions. You say a condition and than if this is true, conditions ensures the same way.
Let’s start with some basic !
static void Main(string[] args)
{
Console.Write(“Enter a number from keyboard: “);
Console.Write(“…..“); is a structure which ensures to write anything from Keyboard.
int number1 = Int32.Parse(Console.ReadLine());
Console.ReadLine(); is a structure which ensures to read anything from Keyboard.
Console.Write(“Enter another number from keyboard: “);
int number2 = Int32.Parse(Console.ReadLine());
Int32.Parse(); is a structure which change the value type anything
Console.WriteLine(“Enter the operation type: “);
char type_of_operation = char.Parse(Console.ReadLine());
double result = 0;
switch (type_of_operation)
{
case ‘+’: result = number1 + number2; break;
case ‘-’: result = number1 + number2; break;
case ‘/’: result = number1 / number2; break;
case ‘x’: result = number1 * number2; break;
default: result= 0;Console.WriteLine(“None”); break;
}
Console.WriteLine(“You faund{0} with operation of type {1} ”, result, type_of_operation);
Console.ReadKey();
}