PC Review


Reply
Thread Tools Rate Thread

how can I use the OR operator or is there another option better thanthis...

 
 
trint
Guest
Posts: n/a
 
      8th May 2009
I need to skip an operation if these conditions are as follows:

if(string1 != string2) or (string1 != string3) or (string1 != string4)
{
do this...
}

I may just have drawn a blank, but your help is appreciated.
Thanks,
Trint
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      8th May 2009
trint wrote:
> I need to skip an operation if these conditions are as follows:
>
> if(string1 != string2) or (string1 != string3) or (string1 != string4)
> {
> do this...
> }
>
> I may just have drawn a blank, but your help is appreciated.


if((string1 != string2) || (string1 != string3) || (string1 != string4))

should be fine.

Arne

 
Reply With Quote
 
trint
Guest
Posts: n/a
 
      9th May 2009
On May 8, 6:46*pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> trint wrote:
> > I need to skip an operation if these conditions are as follows:

>
> > if(string1 != string2) or (string1 != string3) or (string1 != string4)
> > {
> > * do this...
> > }

>
> > I may just have drawn a blank, but your help is appreciated.

>
> if((string1 != string2) || (string1 != string3) || (string1 != string4))
>
> should be fine.
>
> Arne


Thanks. I'll try that.
Trint
 
Reply With Quote
 
Ratnesh Maurya
Guest
Posts: n/a
 
      9th May 2009
On May 9, 4:11*am, trint <trinity.sm...@gmail.com> wrote:
> On May 8, 6:46*pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>
> > trint wrote:
> > > I need to skip an operation if these conditions are as follows:

>
> > > if(string1 != string2) or (string1 != string3) or (string1 != string4)
> > > {
> > > * do this...
> > > }

>
> > > I may just have drawn a blank, but your help is appreciated.

>
> > if((string1 != string2) || (string1 != string3) || (string1 != string4))

>
> > should be fine.

>
> > Arne

>
> Thanks. *I'll try that.
> Trint


Hi Trint,

Better to use if (!string1.equals(string2)) than if(string1!=string2),
if you are checking contents to be equal
you need to take care of null values too.

Cheers,
-Ratnesh
S7 Software
 
Reply With Quote
 
Ratnesh Maurya
Guest
Posts: n/a
 
      9th May 2009
On May 9, 4:11*am, trint <trinity.sm...@gmail.com> wrote:
> On May 8, 6:46*pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
>
> > trint wrote:
> > > I need to skip an operation if these conditions are as follows:

>
> > > if(string1 != string2) or (string1 != string3) or (string1 != string4)
> > > {
> > > * do this...
> > > }

>
> > > I may just have drawn a blank, but your help is appreciated.

>
> > if((string1 != string2) || (string1 != string3) || (string1 != string4))

>
> > should be fine.

>
> > Arne

>
> Thanks. *I'll try that.
> Trint


Hi Trint,

Better to use if (!string1.equals(string2)) than if(string1!=string2),
if you are checking contents to be equal
you need to take care of null values too.

Cheers,
-Ratnesh
S7 Software
 
Reply With Quote
 
not_a_commie
Guest
Posts: n/a
 
      9th May 2009
> Better to use if (!string1.equals(string2)) than if(string1!=string2),
> if you are checking contents to be equal
> you need to take care of null values too.


I'm pretty sure the string class overloads the '!=' and '==' to
compare references and then contents if the reference comparison
fails. Is that not the case? You have to beware of nulls for what you
are suggesting.
 
Reply With Quote
 
not_a_commie
Guest
Posts: n/a
 
      9th May 2009
> Better to use if (!string1.equals(string2)) than if(string1!=string2),
> if you are checking contents to be equal
> you need to take care of null values too.


I'm pretty sure the string class overloads the '!=' and '==' to
compare references and then contents if the reference comparison
fails. Is that not the case? You have to beware of nulls for what you
are suggesting.
 
Reply With Quote
 
Peter Morris
Guest
Posts: n/a
 
      9th May 2009
>>
Better to use if (!string1.equals(string2)) than if(string1!=string2),
if you are checking contents to be equal
you need to take care of null values too.
<<

This approach is likely to suffer from null reference exceptions, whereas
the original != one isn't.



--
Pete
====
http://mrpmorris.blogspot.com
http://www.AlterEgos.com - Who do you want to be?

 
Reply With Quote
 
Peter Morris
Guest
Posts: n/a
 
      9th May 2009
>>
Better to use if (!string1.equals(string2)) than if(string1!=string2),
if you are checking contents to be equal
you need to take care of null values too.
<<

This approach is likely to suffer from null reference exceptions, whereas
the original != one isn't.



--
Pete
====
http://mrpmorris.blogspot.com
http://www.AlterEgos.com - Who do you want to be?

 
Reply With Quote
 
Ratnesh Maurya
Guest
Posts: n/a
 
      11th May 2009
On May 9, 6:40*pm, not_a_commie <notacom...@gmail.com> wrote:
> > Better to use if (!string1.equals(string2)) than if(string1!=string2),
> > if you are checking contents to be equal
> > you need to take care of null values too.

>
> I'm pretty sure the string class overloads the '!=' and '==' to
> compare references and then contents if the reference comparison


No it doesnt, it works because of string "intern pool" the .Net
provides for optimization.
So if you have two string literals containing same string value, then
most probably both of them references to same string literal in intern
pool.
But it is never safe.

> fails. Is that not the case? You have to beware of nulls for what you
> are suggesting.


Yes that is the pain you need to take for good.

Cheers,
-Ratnesh
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
generic problem with operator. compile error: operator * is not allowedon type T. SharpKnight Microsoft C# .NET 2 20th Feb 2006 01:08 PM
The Bang ! operator vs the . operator... Rashar Sharro via AccessMonster.com Microsoft Access Form Coding 10 16th Jun 2005 09:05 PM
Option Commands (Option Explicit / Option Base etc) - Scope Alan Microsoft Excel Programming 8 1st Nov 2004 02:22 AM
making option groups visible/invisible based on another option group selection Emma Microsoft Access Forms 3 24th Jun 2004 05:29 AM
C# exponentiation operator & operator overloading David Laub Microsoft C# .NET 2 20th Dec 2003 09:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:46 PM.