Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a ASP.NET Expert!

Join 244,179 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 1,348 people online right now. Registration is fast and FREE... Join Now!




checking multiple combinations

 
Reply to this topicStart new topic

checking multiple combinations

Trake
29 Aug, 2008 - 04:51 AM
Post #1

D.I.C Head
**

Joined: 29 Jun, 2007
Posts: 72


My Contributions
Hi all,

I want to know if it is possible to check if multiple combinations of values are true for example:
I have 3 boolean values a, b and c andI want to check if a & b are true or a & c are true or b & c are true without doing:

csharp

if (((a == "true") && (b == "true")) || ((a == "true") && (c == "true")) || ((b == "true") && (c == "true")))
{
//do stuff here
}


I know that this example isn't too bad but if there are more than 3 values it starts getting huge (4 is already twice as long as the one above).

Thanks in advance

Ian

User is offlineProfile CardPM
+Quote Post


Jayman
RE: Checking Multiple Combinations
29 Aug, 2008 - 06:00 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,062



Thanked: 159 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Unfortunately, no. However, you can shorten the code. Boolean value comparisons do not require the == "true" part. You can simplify it like the following. Keep in mind that an IF statement evaluates to a boolean answer, as a result you do not need to spell out what it is comparing to when using boolean values.

As you can see it is much shorter and easier to read.
CODE

if ((a && b) || (a && c) || (b && c))
{
}


Hope that helps.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 05:53AM

Live ASP.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

ASP.NET Tutorials

Reference Sheets

ASP.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month