How to convert bool to int in C#

2 Answers

0 votes
using System;

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

            int n = Convert.ToInt32(b);

            Console.WriteLine(n); 
        }
    }
}


/*
run:

1

*/

 



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

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

            int n = Convert.ToInt32(b);

            Console.WriteLine(n); 
        }
    }
}


/*
run:

0

*/

 



answered Jan 2, 2017 by avibootz

Related questions

2 answers 326 views
326 views asked Feb 4, 2021 by avibootz
1 answer 168 views
1 answer 179 views
179 views asked Feb 5, 2021 by avibootz
1 answer 232 views
232 views asked Aug 11, 2019 by avibootz
1 answer 208 views
1 answer 185 views
185 views asked Jan 17, 2017 by avibootz
1 answer 251 views
...