Boolean Values |
Different types of ways to write booleans in C#
Here are some ways I've learned how to write booleans.
What are booleans?
Booleans are true or false values. It can only be set to true or false value, otherwise you need to use another object to represent your value.
Lets take a look at the source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace booleanValues
{
class Program
{
static void Main(string[] args)
{
bool myFirstBoolean = 3 + 2 == 5;
Console.WriteLine(myFirstBoolean.ToString());
bool mySecondBoolean = 3 + 2 > 5;
Console.WriteLine(mySecondBoolean.ToString());
bool bothAreTrue = myFirstBoolean && mySecondBoolean;
Console.WriteLine("bothAreTrue
evaluates " + bothAreTrue);
bool oneIsTrue = (myFirstBoolean || mySecondBoolean);
Console.WriteLine("oneIsTrue
evaluates {0} because one expression is true", oneIsTrue);
bool reverseMyFirstBoolean = !myFirstBoolean;
Console.WriteLine("myFirstBoolean
is {0} but reverseMyFirst is {1}",
myFirstBoolean,
reverseMyFirstBoolean);
Console.ReadLine();
}
}
No comments:
Post a Comment