Polynomial Proton
Polynomial Proton

Reputation: 5135

Are negative numbers considered as null in vb.net?

This might be a stupid question, but I tried finding an answer and did not find anything.

Are negative numbers considered as 'nothing'(null) in vb.net?

Debug mode:

Check this image in debug mode

Above is a query to db to find me all values where the district is 'value'. Its a list in razor view and Since I did not want anything to be displayed by default, I set the district ID to -1 and since there is nothing of that value in the database, it should return anything.

However, it still returns me the value where district is NULL. How is that?

Upvotes: 0

Views: 200

Answers (1)

Origin
Origin

Reputation: 2023

Negative values are not null. However, you are using Or instead of OrElse (http://msdn.microsoft.com/en-us/library/ea1sssb2.aspx)

Or causes both sides of the statement to be called, and it does not short-circuit. Also, you should call the null check before the value check. If you don't short-circuit with the null check, you'll end up calling a comparison of a null value (m.DistrictId) against a non-null value (districtId).

Upvotes: 3

Related Questions