×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

Home » C#.Net

C# Convert.ToInt32(bool) Method - Convert bool value to int

C# Convert.ToInt32(bool) Method: Here, we are going to learn how to convert a bool value to an integer value in C#?
Submitted by IncludeHelp, on February 10, 2019

C# Convert.ToInt32(bool) Method

Convert.ToInt32(bool) Method is used to convert a specific Boolean (bool) value to its equivalent integer (int 32 signed number).

Syntax:

    int Convert.ToInt32(bool value);

It accepts a bool value/variable as an argument and returns its equivalent signed integer.

Example:

    Input: 
    bool a = true;
    Output:
    1

Code:

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Convert.ToInt32(true) : " + Convert.ToInt32(true));
            Console.WriteLine("Convert.ToInt32(false): " + Convert.ToInt32(false));

            bool a = true;
            bool b = false;

            Console.WriteLine("Convert.ToInt32(a) : " + Convert.ToInt32(a));
            Console.WriteLine("Convert.ToInt32(b): " + Convert.ToInt32(b));

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

Convert.ToInt32(true) : 1
Convert.ToInt32(false): 0
Convert.ToInt32(a) : 1
Convert.ToInt32(b): 0
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.