Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IsNothing in C# 1

Status
Not open for further replies.

lfc77

Programmer
Aug 12, 2003
218
GB
What's the C# equivalent of VB IsNothing ?


Thanks,

lfc77
 
Instead of [tt]If IsNothing(blah) Then[/tt] you would do [tt]if (blah != null) {[/tt]
 
Or reverse the sides of the comparison operator if you're like me and occasionally forget to type one of the equals signs:
Code:
if (null == blah)
That way the compiler flags it as trying to assign a value to a constant.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
merlyn2450 -

It's actually a technique that I saw used in MFC programming. The compiler messages in C# are pretty good and usually catch you leaving one of the equals-signs off. In straight C++, the compiler usually doesn't tell you unless the datatypes on both sides are different (in which case you need to be doing a cast anyway). So you end up coding an assignment instead of a comparison, and you don't find out until runtime (uh-oh!).

So, by putting the constant value (if any) on the left-hand side of the comparison operator, you protect yourself against typos.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top