How to use bool (boolean) in C#

3 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            bool b = true;

            if (b)
            {
                Console.WriteLine("true");
            }

            b = !b; 
            if (!b)
            {
                Console.WriteLine("false");
            }
        }
    }
}


/*
run:

true
false

*/

 



answered Jan 2, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            bool b = true;

            Console.WriteLine(b);

            b = !b;

            Console.WriteLine(b);
        }
    }
}


/*
run:

true
false

*/

 



answered Jan 2, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            bool b = true;

            int n = b ? 1 : 0;

            Console.WriteLine(n); 

        }
    }
}


/*
run:

1

*/

 



answered Jan 2, 2017 by avibootz

Related questions

2 answers 241 views
241 views asked Aug 30, 2016 by avibootz
1 answer 161 views
1 answer 172 views
172 views asked Feb 5, 2021 by avibootz
2 answers 320 views
320 views asked Feb 4, 2021 by avibootz
1 answer 203 views
1 answer 179 views
179 views asked Jan 17, 2017 by avibootz
1 answer 243 views
...