Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I've seen a lot of introduction, return true if it meet the requirements , otherwise false, and how to use it in detail?
Define a class, including sex, sex was defined as a Boolean type (Boolean true to indicated male). Than 'private Boolean sex;' Is that right?
Posted
Updated 23-Oct-13 1:03am
v2
Comments
Sergey Alexandrovich Kryukov 22-Oct-13 1:03am    
What "right"? It cannot be right or wrong, it depends on definitions. Boolean is a very basic features present in almost any language, how can it be a matter of any concerns? Anyway, you did not explain your concern, not yet...
—SA
TorstenH. 23-Oct-13 7:05am    
I added the Homework tag. Please show code and ask specific - we will help you.
But your homework is YOUR homework.

Check this
http://en.wikipedia.org/wiki/Boolean_data_type[^]
From wiki:
In computer science, the Boolean or logical data type is a data type, having two values (usually denoted true and false), intended to represent the truth values of logic and Boolean algebra.

As stated above, boolean is for two values things(true/false).
For example, if you want to check the status of something like IsActive, IsAdmin, IsNegativeStock, IsEmpty, IsFull, etc.,
See the sample one below.
C#
bool bAdmin;

public void SomeMethod()
{
  bAdmin = IsAdmin();
}
public bool IsAdmin()
{
//Code for checking the user is admin or not
//true - Admin user, false - Normal user
}

In your case, Gender is not suitable for boolean. Following are values for Gender field.
Male
Female
Transgender(Transman, Transwomen)
Unspecified
etc.,(I forgot one more value)

I have seen few websites that showing Gender dropdown with above mentioned values so Gender is not suitable for boolean.
In database side, I don't use bit datatype, instead I use someother datatype like char or int depends upon data. Because in past, we have used bit datatype for some columns but in one situation end user wanted to store some more values, so we had to use some other data type.
 
Share this answer
 
Quote:
Define a class, including sex, sex was defined as a Boolean type (Boolean true to indicated male). Than 'private Boolean sex;' Is that right?


That is really poor naming (and is not even politically correct :-) ).
You should define a boolean class member named female with the following meaning:
  • true: is female.
  • false: is NOT female.
 
Share this answer
 
You really shouldn't use Boolean on that one, even if you name ur attribute 'isMale', false means its not Male which can be Female or something else like transgender. Try to look something like Enums, might suit better your solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900