Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert a specified value to an equivalent Boolean value in C#
To convert a specified value to an equivalent Boolean value, the code is as follows −
Example
using System;
using System.Globalization;
public class Demo {
public static void Main() {
CultureInfo cultures = new CultureInfo("en-US");
String str = "true";
Console.WriteLine("Converted bool value...");
bool res = Convert.ToBoolean(str, cultures);
Console.Write("{0}", res);
}
}
Output
This will produce the following output −
Converted bool value... True
Example
Let us see another example −
using System;
using System.Globalization;
public class Demo {
public static void Main() {
CultureInfo cultures = new CultureInfo("es-ES", false);
String str = "false";
Console.WriteLine("Converted bool value...");
bool res = Convert.ToBoolean(str, cultures);
Console.Write("{0}", res);
}
}
Output
This will produce the following output −
Converted bool value... False
Advertisements