IIF to the rescue...
-
It is a function on the
Order
class, but it still takes a parameter (it just getsmOrderNumber
given to it every time). VB does not have a ternary operator. I'm saying the function could look like this:Return OrderNumber = 0
There is no need for anIIF
anywhere in the code. As I said, it's not truly horrible, but it's an 'interesting' way to return ifOrderNumber = 0
:)It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}Ah, thanks. That explains it. It really deserves this place.
-
Ah, thanks. That explains it. It really deserves this place.
Don't worry, we all have our off-days :laugh:
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
It is a function on the
Order
class, but it still takes a parameter (it just getsmOrderNumber
given to it every time). VB does not have a ternary operator. I'm saying the function could look like this:Return OrderNumber = 0
There is no need for anIIF
anywhere in the code. As I said, it's not truly horrible, but it's an 'interesting' way to return ifOrderNumber = 0
:)It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}Sander Rossel wrote:
VB does not have a ternary operator.
It does, it's the
IIf
function/method/whateva -
Sander Rossel wrote:
VB does not have a ternary operator.
It does, it's the
IIf
function/method/whatevaIs that an operator or a function? ;) I wouldn't know the difference, but I believe there is one. Something like an operator is a function, but a function is not an operator.
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
Sander Rossel wrote:
VB does not have a ternary operator.
It does, it's the
IIf
function/method/whatevaNot quite.
IIf
is a function[^], and as such it evaluates both arguments before checking the condition. So while this works in C#:someObject == null ? "Null" : someObject.ToString()
the equivalent using
IIf
will throw aNullReferenceException
:IIf(someObject Is Nothing, "Null", someObject.ToString()) ' Boom!
The real ternary operator for VB.NET is the
If
operator[^], which was added in .NET 3.5:If(someObject Is Nothing, "Null", someObject.ToString()) ' No Boom.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Don't worry, we all have our off-days :laugh:
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}I guess it was an unhandled
ConfusedByVBException
... -
I guess it was an unhandled
ConfusedByVBException
...:laugh:
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
It is a function on the
Order
class, but it still takes a parameter (it just getsmOrderNumber
given to it every time). VB does not have a ternary operator. I'm saying the function could look like this:Return OrderNumber = 0
There is no need for anIIF
anywhere in the code. As I said, it's not truly horrible, but it's an 'interesting' way to return ifOrderNumber = 0
:)It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}I don't know VB and was just wondering ... if
Return OrderNumber = 0
does a comparison and returns the result then how would you set the value of OrderNumber to 0 and then return OrderNumber? In C#, the first is
return OrderNumber == 0;
and the second is
return OrderNumber = 0;
-
I don't know VB and was just wondering ... if
Return OrderNumber = 0
does a comparison and returns the result then how would you set the value of OrderNumber to 0 and then return OrderNumber? In C#, the first is
return OrderNumber == 0;
and the second is
return OrderNumber = 0;
PaulLinton wrote:
I don't know VB
Obviously :) VB doesn't know the
==
operator. Instead=
can be either assignment or comparison, dependent on context. In this case it's a comparison, but no assignment. SoReturn OrderNumber = 0
Would be
return OrderNumber == 0;
in C#. Your second C# example isn't possible in VB (as far as I know, but I didn't know it was possible in C# either :) )
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
PaulLinton wrote:
I don't know VB
Obviously :) VB doesn't know the
==
operator. Instead=
can be either assignment or comparison, dependent on context. In this case it's a comparison, but no assignment. SoReturn OrderNumber = 0
Would be
return OrderNumber == 0;
in C#. Your second C# example isn't possible in VB (as far as I know, but I didn't know it was possible in C# either :) )
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}The second one would be:
Return (Ordernumber = 0)
<edit>Or like this:
Return 0 = Ordernumber
</edit>
Wrong is evil and must be defeated. - Jeff Ello[^]