
You want to return true or false from a method or property in your C# program, and are wondering ways you can enhance your code with greater abstraction. Returning true and false from a method is a way to improve the object-orientation of your application and simplify it.
This C# example program shows methods and properties that return bools.

Here we declare a class that has several fields, which determine its state. When you have complex classes, you can expose public methods that return calculated bool values. Often, developers will use the "Is" prefix, to indicate the type of result. It is usually clearest to phrase all boolean properties and methods in the positive, and then test them for false if required.
Class methods that return true and false [C#]
using System;
class Employee
{
bool _fired = false;
bool _hired = true;
int _salary = 10000;
public bool IsCurrent()
{
return !this._fired &&
this._hired &&
this._salary > 0;
}
public bool IsExecutive()
{
return IsCurrent() &&
this._salary > 1000000;
}
public bool Fired
{
get
{
return this._fired;
}
}
}
class Program
{
static void Main()
{
Employee employee = new Employee();
if (employee.IsCurrent())
{
Console.WriteLine("Is currently employed");
}
if (employee.IsExecutive())
{
Console.WriteLine("Is an executive");
}
if (!employee.Fired)
{
Console.WriteLine("Is not fired yet");
}
}
}
Output
Is currently employeed
Is not fired yetDescription. The Employee class contains three member variables, including two bools and an integer. The methods IsCurrent(), IsEmployee() and the property Fired provide an abstraction of the internal state of the object. When you return boolean values, you can chain expressions with logical AND and OR.

Note on the Fired property. This property simply returns the value of the internal state member with the same name. In C# programs, using properties allows you more flexibility when changing the internal implementation of classes without affecting other parts of your program.
The bool type is a common type to use as the return type in methods in C# programs. The class above provides the syntax for this pattern. Next, we look at the logic and established wisdom regarding boolean result values and methods that return bools.

Code Complete book. "Understanding complicated boolean tests in detail is rarely necessary for understanding program flow. Putting such a test into a function makes the code more readable because 1) the details of the test are out of the way and 2) a descriptive function name summarizes the purpose of the test." Please see Code Complete, 2nd Edition by Steve McConnell; page 165.
Code Complete: Book Review
We looked at an example of a class that contains methods and properties returning bools in the C# language. We discussed the principles of abstraction in object-oriented programming, and researched the topic in one of the leading books about software construction. Additionally, we saw how you can chain these conditional expressions for the clearest code.
Return Statement Bool Type