Skip to main content
added 77 characters in body
Source Link
NPSF3000
  • 715
  • 3
  • 9

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which in addition to performance considerations might change its result between calls or have side effects!)

bool swap = tag.Equals(pathBallTagName);
GameObject newBall = swap ? other.gameObject : gameObject;
GameObject pathBall = swap ? gameObject : other.gameObject;

Alternatively one could implement a Swap function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) Swap (ref newBall, ref pathBall);

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which might change its result!)

bool swap = tag.Equals(pathBallTagName);
GameObject newBall = swap ? other.gameObject : gameObject;
GameObject pathBall = swap ? gameObject : other.gameObject;

Alternatively one could implement a Swap function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) Swap (ref newBall, ref pathBall);

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which in addition to performance considerations might change its result between calls or have side effects!)

bool swap = tag.Equals(pathBallTagName);
GameObject newBall = swap ? other.gameObject : gameObject;
GameObject pathBall = swap ? gameObject : other.gameObject;

Alternatively one could implement a Swap function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) Swap (ref newBall, ref pathBall);
deleted 37 characters in body
Source Link
NPSF3000
  • 715
  • 3
  • 9

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which might change its result!)

bool @switchswap = tag.Equals(pathBallTagName); // switch is a keyword
GameObject newBall = @switchswap ? other.gameObject : gameObject;
GameObject pathBall = @switchswap ? gameObject : other.gameObject;

Alternatively one could implement a SwitchSwap function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) SwitchSwap (ref newBall, ref pathBall);

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which might change its result!)

bool @switch = tag.Equals(pathBallTagName); // switch is a keyword
GameObject newBall = @switch ? other.gameObject : gameObject;
GameObject pathBall = @switch ? gameObject : other.gameObject;

Alternatively one could implement a Switch function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) Switch (ref newBall, ref pathBall);

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which might change its result!)

bool swap = tag.Equals(pathBallTagName);
GameObject newBall = swap ? other.gameObject : gameObject;
GameObject pathBall = swap ? gameObject : other.gameObject;

Alternatively one could implement a Swap function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) Swap (ref newBall, ref pathBall);
switch is a keyword in C#. Editing the sample code to make it syntactically correct.
Source Link

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which might change its result!)

bool switch@switch = tag.Equals(pathBallTagName); // switch is a keyword
GameObject newBall = switch@switch ? other.gameObject : gameObject;
GameObject pathBall = switch@switch ? gameObject : other.gameObject;

Alternatively one could implement a Switch function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) Switch (ref newBall, ref pathBall);

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which might change its result!)

bool switch = tag.Equals(pathBallTagName);
GameObject newBall = switch ? other.gameObject : gameObject;
GameObject pathBall = switch ? gameObject : other.gameObject;

Alternatively one could implement a Switch function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) Switch (ref newBall, ref pathBall);

One alternative, note how we must store the bool result to ensure identical semantics (otherwise you risk calling tag.Equals twice... which might change its result!)

bool @switch = tag.Equals(pathBallTagName); // switch is a keyword
GameObject newBall = @switch ? other.gameObject : gameObject;
GameObject pathBall = @switch ? gameObject : other.gameObject;

Alternatively one could implement a Switch function elsewhere:

GameObject newBall = other.gameObject;
GameObject pathBall = gameObject;
if (tag.Equals(pathBallTagName)) Switch (ref newBall, ref pathBall);
Source Link
NPSF3000
  • 715
  • 3
  • 9
Loading