Professional Documents
Culture Documents
8 is bigger than 2
How to clean code with Variables
In code we don’t like magic numbers so we use variables!
int a = 8;
int b = 2;
If (a >= b)
{
Console.WriteLine(a + ”is bigger than” + b);
} else
{
Console.WriteLine(a + “is not bigger than” + b);
}
Output:
8 is bigger than 2
How to clean code with Variables
We can change the variable and the rest of the code follow
int a = 10;
int b = 3;
If (a >= b)
{
Console.WriteLine(a + ”is bigger than” + b);
} else
{
Console.WriteLine(a + “is not bigger than” + b);
}
Output:
10 is bigger than 3
Making Code more flexible
We can use user-input to gather and use data for our own.
Console.WriteLine("first number:");
string a = Console.ReadLine();
Console.WriteLine("second number");
string b = Console.ReadLine();
first number:
7 (type any number and press enter)
second number:
8 (type any number and press enter)
7 is not bigger than 8.