C# Lesson 1
Learn how to declare and use variables in the very first lesson from our series on learning C# for beginners.
Author
You truly need this lesson from our beginner series if you aren't familiar with using a Boolean in C#.
In Lesson 4 I'll be introducing another datatype. The bool!
Afterwards you can continue to the next lesson!
Or go back and review the previous lesson.
We also have the source code on GitHub.
using System;
namespace Lesson4
{
class TrueAndFalse
{
static void Main(string[] args)
{
// true, false
// 1 , 0
bool trueValue = true;
Console.WriteLine("This is a true value:\t" + trueValue);
bool falseValue = false;
Console.WriteLine("This is a false value:\t" + falseValue);
/* Comparison Operators
* ==, IS EQUAL TO
* !=, IS NOT EQUAL TO
* >, GREATER THAN
* <, LESS THAN
* >=, GREATER THAN OR EQUAL TO
* <=, LESS THAN OR EQUAL TO
*/
bool value1 = 7 == 7;
Console.WriteLine("7 IS EQUALE TO 7:\t" + value1);
bool value2 = 7 != 7;
Console.WriteLine("7 IS NOT EQUAL TO 7: \t" + value2);
bool value3 = 99 > 1;
Console.WriteLine("99 IS GREATER THAN 1:\t" + value3);
bool value4 = 99 < 1;
Console.WriteLine("99 IS LESS THAN 1:\t" + value4);
bool value5 = 2 >= 1;
Console.WriteLine("2 is greaterthan or equal to 1: " + value5);
bool value6 = 2 <= 2;
Console.WriteLine("2 is lessthan or equal to 2: " + value6);
bool value7 = "cup" == "CUP";
Console.WriteLine("cup is equal to CUP: " + value7);
}
}
}
/*
* TASK:
* Below, you will see comparison statements written in english being displayed by Console.WriteLine.
* Make a bool variable that executes the comparison described in the Console.WriteLine.
* Then concatinate the bool to the end of the string.
*/
using System;
namespace Lesson4Task
{
class TrueAndFalseTask
{
static void Main(string[] args)
{
Console.WriteLine("7 is greater than 9: ");
Console.WriteLine("12 is less than 15: ");
Console.WriteLine("91 is greater than or equal to 19: ");
Console.WriteLine("1.2 is not equal to 6.6: ");
Console.WriteLine("17.9 is less than or equal to 17.91: ");
Console.WriteLine("7.5 is greater than 7.4: ");
Console.WriteLine("ball equals BALL: ");
Console.WriteLine("cup equals cup: ");
Console.WriteLine("pan is not equal to Pan: ");
}
}
}
We have similar articles. Keep reading!
Learn how to declare and use variables in the very first lesson from our series on learning C# for beginners.
Author
Learn how to read input from the user in the second lesson from our series on learning C# for beginners.
Author
Learn how to do some basic math with C# in the 3rd lesson from our series for beginners learning C#.
Author