ASP.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

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

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




checking multiple combinations

 

checking multiple combinations

Trake

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

D.I.C Head
**

Joined: 29 Jun, 2007
Posts: 80


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,544



Thanked: 226 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: 11/8/09 03:30AM

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