This data type is used to store whole numbers without decimals in C#.
What is int
Console.WriteLine(3 + 5);
what is 8?
int x = 10;
if (x > 5)
{
Console.WriteLine("Greater than 5");
}
else
{
Console.WriteLine("Less than or equal to 5");
}
What is Greater than 5?
string firstName = "John";
string lastName = "Doe";
string fullName = firstName + " " + lastName;
Console.WriteLine(fullName);
What is John Doe?
for (int i = 1; i <= 5; i++)
{
Console.Write(i + " ");
}
What is 1 2 3 4 5 ?
This floating-point data type is commonly used in C# to store numbers with decimals but offers less precision than double.
What is float
Console.WriteLine(10 - 4);
what is 6?
int x = 8;
if (x % 2 == 0)
{
Console.WriteLine("Even");
}
else
{
Console.WriteLine("Odd");
}
What is Even?
bool isSunny = true;
bool isWeekend = false;
bool canGoOutside = isSunny && isWeekend;
Console.WriteLine(canGoOutside);
What is false?
for (int i = 5; i > 0; i--)
{
Console.Write(i + " ");
}
What is 5 4 3 2 1 ?
This data type can store a single Unicode character and is enclosed in single quotes.
What is char?
int x = 9;
int y = 5;
Console.WriteLine($"{x * y}");
What is 45?
int a = 4;
int b = 6;
if (a + b > 10)
{
Console.WriteLine("Sum is greater than 10");
}
else
{
Console.WriteLine("Sum is 10 or less");
}
What is sum is 10 or less?
double price = 49.99;
double discount = 10.0;
double finalPrice = price - (price * discount / 100);
Console.WriteLine(finalPrice);
What is 44.99?
for (int i = 1; i <= 10; i += 2)
{
Console.Write(i + " ");
}
What is 1 3 5 7 9 ?)
This immutable data type in C# represents a sequence of characters.
What is string?
float a = 2;
float b = 3;
float c = a * b + b / a;
Console.WriteLine(c);
what is 7.5?
int num = 7;
if (num % 3 == 0)
{
Console.WriteLine("Divisible by 3");
}
else if (num % 5 == 0)
{
Console.WriteLine("Divisible by 5");
}
else
{
Console.WriteLine("Not divisible by 3 or 5");
}
What is Not divisible by 3 or 5?
double pi = 3.14;
double radius = 2.5;
double area = pi * radius * radius;
Console.WriteLine(area);
What is 19.625?
int result = 1;
for (int i = 3; i >= 1; i--)
{
result *= i;
}
Console.WriteLine(result);
What is 6?
This data type can store one of only two possible values.
What is bool
int a = 2;
int b = 3;
int result = (a + b) * (b - a);
Console.WriteLine(result);
What is 5?
int x = 12;
int y = 4;
if (x % y == 0 && x / y > 2)
{
Console.WriteLine("Perfectly divisible and > 2");
}
else
{
Console.WriteLine("Not divisible or <= 2");
}
What is Perfectly divisible and > 2?
int apples = 4;
int bananas = 6;
int fruits = apples + bananas;
Console.WriteLine(fruits);
What is 10?
int x = 2;
for (int i = 1; i <= 3; i++)
{
x *= i;
}
Console.WriteLine(x);
What is 12?