.NETGURU
combine compare statements
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Yannick Smits
How would I write the following line in a more neat way?

if ( myDataType == "int" || myDataType == "smallint" )

something like this pseudocode:

if ( myDataType == ("int" || "smallint") )

Thanks,
Yannick Smits

Reply to this message...
 
    
chris
Just off the top of my head, do you think the XOR operator would work? eg.

if(myDataType == ("int" | "smallint"))

-Chris Frazier
.NET Solution Developer
Velocity Databank, Inc.
www.velocitydatabank.com

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Monday, August 12, 2002 12:01 PM
To: aspngcs
Subject: [aspngcs] combine compare statements

How would I write the following line in a more neat way?

if ( myDataType == "int" || myDataType == "smallint" )

something like this pseudocode:

if ( myDataType == ("int" || "smallint") )

Thanks,
Yannick Smits

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
leon jollans
perhaps in a switch statement?

switch (myDataType){

case "int":
case "smallint":
HandleIntegralTypes();
break;
case "varchar":
HandleVarChar();
break;
case default:
    HandleUnrecognized();
break;

}

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: 12 August 2002 18:01
To: aspngcs
Subject: [aspngcs] combine compare statements

How would I write the following line in a more neat way?

if ( myDataType =3D=3D "int" || myDataType =3D=3D "smallint" )

something like this pseudocode:

if ( myDataType =3D=3D ("int" || "smallint") )

Thanks,
Yannick Smits

| [aspngcs] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT

Reply to this message...
 
    
Yannick Smits
This one doesn't work:
Operator '|' cannot be applied to operands of type 'string' and 'string'

Any other suggestions?
Thanks,
Yannick Smits

"chris" <Click here to reveal e-mail address> wrote in message news:696733@aspngcs...
[Original message clipped]

Reply to this message...
 
    
James Shaw (VIP)
Why not encapsulate it by creating a bool property called IsInteger and do
the comparison in there. At least your clients would see tidier code.

public bool IsInteger()
{
    get { return ( myDataType == "int" || myDataType == "smallint" ); }
}

James Shaw
http://CoverYourASP.com/
Download it. Run it. Learn it.
http://ASPRSS.com/
Publish ASP with RSS XML

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Monday, August 12, 2002 4:06 PM
To: aspngcs
Subject: [aspngcs] Re: combine compare statements

This one doesn't work:
Operator '|' cannot be applied to operands of type 'string' and 'string'

Any other suggestions?
Thanks,
Yannick Smits

"chris" <Click here to reveal e-mail address> wrote in message news:696733@aspngcs...
[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Moore, Dot Net Guruhew
Are there other possibilities of words that would cause a problem that you wouldn't want such as longint? If not, I would think you could compare it to the last 3 characters of the string to see if it is == "int" but if it could be longint or some other ....int, then this approach wouldn't work. :(

Dot Net Guru

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Monday, August 12, 2002 4:06 PM
To: aspngcs
Subject: [aspngcs] Re: combine compare statements

This one doesn't work:
Operator '|' cannot be applied to operands of type 'string' and 'string'

Any other suggestions?
Thanks,
Yannick Smits

"chris" <Click here to reveal e-mail address> wrote in message news:696733@aspngcs...
[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Josh Howe
>if( myDataType == ("int" || "smallint") )

You can't apply Boolean operators to strings - a string isn't true or false,
it just is. It looks like what you're really trying to do is see if
myDataType is in the set {"int","smallint"}. You could put "int" and
"smallint" into a set-based class - most set based classes have a contains()
method. But I think that might be overkill if there are only two values -
if( myDataType == "int" || myDataType == "smallint" ) is probably the way to
go.

-----Original Message-----
From: Yannick Smits [mailto:Click here to reveal e-mail address]
Sent: Monday, August 12, 2002 4:06 PM
To: aspngcs
Subject: [aspngcs] Re: combine compare statements

This one doesn't work:
Operator '|' cannot be applied to operands of type 'string' and 'string'

Any other suggestions?
Thanks,
Yannick Smits

"chris" <Click here to reveal e-mail address> wrote in message news:696733@aspngcs...
[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

DISCLAIMER: The information contained herein is confidential and is intended
solely for the addressee(s). It shall not be construed as a recommendation
to buy or sell any security. Any unauthorized access, use, reproduction,
disclosure or dissemination is prohibited. Neither ISLAND nor any of its
subsidiaries or affiliates shall assume any legal liability or
responsibility for any incorrect, misleading or altered information
contained herein. Thank you.

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification