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 233 views
233 views asked Aug 30, 2016 by avibootz
1 answer 150 views
1 answer 164 views
164 views asked Feb 5, 2021 by avibootz
2 answers 312 views
312 views asked Feb 4, 2021 by avibootz
1 answer 192 views
1 answer 171 views
171 views asked Jan 17, 2017 by avibootz
1 answer 232 views
...