Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 05-03-2006, 11:26 PM   #1 (permalink)
Account Terminated
 
Join Date: Sep 2002
Location: New York
Age: 22
Posts: 476
Default x == (y || z)

if (x == (y || z))

Is there a way to get something like that besides

if (x == y || x == z)
Dipset is offline   Reply With Quote
Old 05-03-2006, 11:45 PM   #2 (permalink)
RunUO Forum Moderator
 
daat99's Avatar
 
Join Date: Dec 2004
Location: Israel
Age: 27
Posts: 8,163
Send a message via ICQ to daat99 Send a message via AIM to daat99
Default

Quote:
Originally Posted by Dipset
if (x == (y || z))

Is there a way to get something like that besides

if (x == y || x == z)
Not in c#, sorry.
__________________
I always try to help
Sometimes, I don't know how....

My Web Page
Forum Rules
-------------------------------------------------------------
Extensive OWLTR System | Token System | World Teleporters
-------------------------------------------------------------
daat99 is offline   Reply With Quote
Old 05-04-2006, 11:14 AM   #3 (permalink)
Forum Newbie
 
Join Date: Jun 2005
Age: 31
Posts: 45
Default

[x & (y || z)] || [!x & (!y & !z)]
yarex is offline   Reply With Quote
Old 05-04-2006, 12:32 PM   #4 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Whats wrong with?

Code:
if (x == y || x == z)
What you want to do, and what you asked, does exactly the samething so I perhaps don't understand why the method that does work is not something you want to use.
Phantom is offline   Reply With Quote
Old 05-04-2006, 01:13 PM   #5 (permalink)
Forum Expert
 
wieganka's Avatar
 
Join Date: Oct 2004
Location: Chesterton, IN
Age: 29
Posts: 288
Default

Quote:
Originally Posted by Phantom
Whats wrong with?

Code:
if (x == y || x == z)
What you want to do, and what you asked, does exactly the samething so I perhaps don't understand why the method that does work is not something you want to use.
I believe that this is a question of being more "efficient" (or lazy, whichever you prefer). The poster wanted to know if there was a shorter way of writing:

Code:
if (x == y || x == z)
Which, of course, in C#, there isn't.
wieganka is offline   Reply With Quote
Old 05-04-2006, 01:21 PM   #6 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by wieganka
I believe that this is a question of being more "efficient" (or lazy, whichever you prefer). The poster wanted to know if there was a shorter way of writing:

Code:
if (x == y || x == z)
Which, of course, in C#, there isn't.
I don't understand whats wrong with it....
Phantom is offline   Reply With Quote
Old 05-04-2006, 06:01 PM   #7 (permalink)
Forum Expert
 
wieganka's Avatar
 
Join Date: Oct 2004
Location: Chesterton, IN
Age: 29
Posts: 288
Default

There's absolutely nothing wrong with it. They were just looking for a shorter way of writing it.
wieganka is offline   Reply With Quote
Old 05-04-2006, 06:24 PM   #8 (permalink)
Account Terminated
 
Join Date: Sep 2002
Location: New York
Age: 22
Posts: 476
Default

if (x == y || x == z) looks fucking ugly and is a waste of text.
Dipset is offline   Reply With Quote
Old 05-04-2006, 06:34 PM   #9 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by Dipset
if (x == y || x == z) looks fucking ugly and is a waste of text.
If you say so, but considering there isn't another way to do an OR statement, its not a waste of text.
Phantom is offline   Reply With Quote
Old 05-04-2006, 06:55 PM   #10 (permalink)
Forum Expert
 
Join Date: Feb 2005
Age: 24
Posts: 985
Send a message via AIM to Nochte
Default

Quote:
Originally Posted by Dipset
if (x == y || x == z) looks fucking ugly and is a waste of text.
you're kidding, right?
__________________
Quote:
Originally Posted by kkjjkk View Post
how sad you people call yourselves scripters and you can't even format an emulator game into something completely differnt....no wounder y'all are stuck here with no real scripting jobs unlike me. please go back to school.
QFDA
Nochte is offline   Reply With Quote
Old 05-04-2006, 07:33 PM   #11 (permalink)
Forum Expert
 
wieganka's Avatar
 
Join Date: Oct 2004
Location: Chesterton, IN
Age: 29
Posts: 288
Default

Quote:
Originally Posted by Dipset
if (x == y || x == z) looks fucking ugly and is a waste of text.
I don't even want to get in on this one....sheesh...
wieganka is offline   Reply With Quote
Old 05-04-2006, 08:02 PM   #12 (permalink)
Forum Newbie
 
Join Date: Jun 2005
Age: 31
Posts: 45
Default

(x == y || x == z) is wrong.

x == (y || z) .... when x ==0 and y ==1 and z==0
0 == (1||0) .... = (0==1) = 0. so it gives false

but when its (x == y || x == z)

(0 == 1 || 0==0) ....... (0 || 1) = 1

So these two are not equal in case if x=0 and y=1 and z=0
or case
x=0 and y=0 and x=1
(other cases are ok )
yarex is offline   Reply With Quote
Old 05-04-2006, 09:00 PM   #13 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,818
Default

Quote:
Originally Posted by Dipset
if (x == y || x == z) looks fucking ugly and is a waste of text.
That accually made me laugh out loud irl hahaha great.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 05-04-2006, 10:50 PM   #14 (permalink)
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

Quote:
Originally Posted by yarex
(x == y || x == z) is wrong.

x == (y || z) .... when x ==0 and y ==1 and z==0
0 == (1||0) .... = (0==1) = 0. so it gives false

but when its (x == y || x == z)

(0 == 1 || 0==0) ....... (0 || 1) = 1

So these two are not equal in case if x=0 and y=1 and z=0
or case
x=0 and y=0 and x=1
(other cases are ok )
Yes, but in his case, the semantics of
Code:
x == y || x == z
is what he was looking for, just in a shorter way of doing it, so the semantics that you pointed out, while valid in certain situations, was not what he was looking for.


Now, back to the topic, you can doing something like
Code:
x == (y || z)
But not normally and not all too pretty (nor without abusing the privilege of overloading operators). I felt like screwing with C#'s overloading of operators and wanted to see if you could abuse it in somewhat the same way as in C++, and I'm happy to say that you can, to a degree.

Code:
class TestClass
{
	public TestClass ( int i1, int i2 )
	{
		x = i1;
		y = i2;
	}
		
	public static bool operator == ( int i, TestClass tc )
	{
		return (i == tc.x || i == tc.y);
	}

	public static bool operator != ( int i, TestClass tc )
	{
		return !(i == tc);
	}

	int x
	        , y;
}

class TestClass2
{
	public TestClass2 ( int i )
	{
		x = i;
	}

	public static TestClass operator | ( TestClass2 tc1, TestClass2 tc2 )
	{
		return new TestClass( tc1.x, tc2.x );
	}
	
	public int x;
}
Using these two classes together, it's possible for me to write something of the form
Code:
int i = 20;
TestClass2 tc1 = new TestClass2(10)
        , tc2 = new TestClass2(20);

i == (tc1 | tc2);
and have it be semantically equivalent to
Code:
i == tc1.x || i == tc2.x
Please note that I do not advocate doing this, as it is indeed a bit of a misuse of the powerful and easily abusable operator overloading concept.

However, do note that I love that you can do this.

Last edited by Sep102; 05-04-2006 at 11:03 PM.
Sep102 is offline   Reply With Quote
Old 05-04-2006, 10:55 PM   #15 (permalink)
Moderate
 
David's Avatar
 
Join Date: Nov 2002
Location: USA
Posts: 6,598
Default

Quote:
Originally Posted by Dipset
if (x == y || x == z) looks fucking ugly and is a waste of text.
As opposed to what, this thread maybe?
__________________
David Forum Moderator
The RunUO.com Forum Moderator Team

Forum Rules and Guidelines
RunUO Forum Search Engine
Download RunUO 2.0 RC2
David is offline   Reply With Quote
Old 05-05-2006, 10:22 PM   #16 (permalink)
Forum Expert
 
FingersMcSteal's Avatar
 
Join Date: Mar 2006
Location: North East, England, UK
Posts: 854
Send a message via ICQ to FingersMcSteal Send a message via MSN to FingersMcSteal
Default

Quote:
Originally Posted by Dipset
if (x == y || x == z) looks fucking ugly and is a waste of text.
Best answer i've read in a long time
__________________
We can be found on joinUO.com or listUO.com, come try us out.
FingersMcSteal is offline   Reply With Quote
Old 05-05-2006, 10:32 PM   #17 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by yarex
(x == y || x == z) is wrong.

x == (y || z) .... when x ==0 and y ==1 and z==0
0 == (1||0) .... = (0==1) = 0. so it gives false

but when its (x == y || x == z)

(0 == 1 || 0==0) ....... (0 || 1) = 1

So these two are not equal in case if x=0 and y=1 and z=0
or case
x=0 and y=0 and x=1
(other cases are ok )
Your example its actually wrong, because 0 == 0 is true, and thus the if statement is true.

What he wants is if x is equal to y or z, then the statement would be true, which is what has been posted.
Phantom is offline   Reply With Quote
Old 05-06-2006, 12:03 AM   #18 (permalink)
Account Terminated
 
Join Date: Sep 2002
Location: New York
Age: 22
Posts: 476
Default

Quote:
Originally Posted by David
As opposed to what, this thread maybe?
Yes, I asked a simple question and everyone goes on and on about random shit.

This shouldn't have gone past daat99's reply.
Dipset is offline   Reply With Quote
Old 05-06-2006, 12:10 AM   #19 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by Dipset
Yes, I asked a simple question and everyone goes on and on about random shit.

This shouldn't have gone past daat99's reply.
I just wanted to know why he didn't want to use it.

Now that I know, I wish I didn't because its a lame reason
Phantom is offline   Reply With Quote
Old 05-06-2006, 09:17 AM   #20 (permalink)
Forum Newbie
 
Join Date: Jun 2005
Age: 31
Posts: 45
Default

Quote:
Originally Posted by Phantom
Your example its actually wrong, because 0 == 0 is true, and thus the if statement is true.

What he wants is if x is equal to y or z, then the statement would be true, which is what has been posted.
If you mean this:
(0 == 1 || 0==0) ....... (0 || 1) = 1

then think again, becouse you are wrong.

0==1 gives 0
0==0 gives 1
therefore i've written that its equal to (0 || 1) = 1 = true

Result is the same as you say, but looks like you think something different.
yarex is offline   Reply With Quote
Old 05-06-2006, 09:38 AM   #21 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

I don't understand what your saying about what I said is incorrect.

You said the following:
0 == (1||0) .... = (0==1) = 0. so it gives false

Looking at it again, I see thats actually is infact true, you do understand that || stands for OR correct? If the OR statement was an bit-wsie OR statement then it would be false. But its not and 0==0 is a true statement.
Phantom is offline   Reply With Quote
Old 05-06-2006, 12:48 PM   #22 (permalink)
Forum Expert
 
Join Date: Aug 2004
Location: Redmond, WA
Age: 21
Posts: 1,288
Send a message via AIM to Sep102 Send a message via MSN to Sep102
Default

Perhaps this would clarify his statement a bit better

We have:
Code:
false == (true || false);
Now, first we evaluate the (true || false):
Code:
(true || false) = true
Next we evaluate the rest of the statement, substituting in the first part we evaluated:
Code:
false == (true || false) = false == true = false
So, therefore, in his statement he is correct in that it does indeed evaluate to false.
Sep102 is offline   Reply With Quote
Old 05-06-2006, 06:41 PM   #23 (permalink)
Account Terminated
 
Join Date: Sep 2002
Location: New York
Age: 22
Posts: 476
Default

You guys take things a bit to far.
Dipset is offline   Reply With Quote
Old 05-07-2006, 06:03 AM   #24 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by Sep102
Perhaps this would clarify his statement a bit better

We have:
Code:
false == (true || false);
Now, first we evaluate the (true || false):
Code:
(true || false) = true
Next we evaluate the rest of the statement, substituting in the first part we evaluated:
Code:
false == (true || false) = false == true = false
So, therefore, in his statement he is correct in that it does indeed evaluate to false.
See the problem with your the statement its "false" is beause the statement itself is incorrect. Your doing an operation that is illegal in a sense. Taking the statement into context, what the real value is, is what the correct statement would do.

I am still going to say your incorrect for saying its false.
Phantom is offline   Reply With Quote
Old 05-07-2006, 09:33 PM   #25 (permalink)
Forum Expert
 
Join Date: Sep 2002
Age: 23
Posts: 1,472
Default

Code:
	switch(x)
	{
		case y:
		case z:
		{
		
		} break;
	}
:P
Ravatar is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools