c# Is Nothing equiv

  • Thread starter Thread starter mp
  • Start date Start date
M

mp

in vb6

Dim o As Object
If o Is Nothing Then

in C# ???
Object o;
If (o == null)
{}

is that correct?
 
Peter Duniho said:
Yes, that is correct.


thanks,
i just noticed that even with strings (since they're now objects) instead of
If thisString.Length = 0 .... //blank string
is now...
if thisString = = null ....
still trying to get my rudimentary vb6 brain to think in dotnet
:-)
mark
 
Peter Duniho said:
No. That's not true. In both VB.NET _and_ C#, there's a big difference
between "If thisString.Length = 0"/"if (thisString.Length == 0)" and "If
thisString Is Nothing"/"if (thisString == null)".

I don't recall the specific rules for strings in VB6. Maybe it's not
possible to have a null reference in VB6. But in VB.NET, it definitely
is. VB.NET and C# are practically identical in many respects, because
they are both built on top of the .NET Framework libraries. And pretty
much anything to do with System.String (since it's part of the .NET
Framework libraries) is going to work the same in either language.

If you want to treat a null reference the same as an empty string, you
would use the static method System.String.IsNullOrEmpty(). That checks
for both conditions, returning true if either is true.

Pete


thanks again!
mark
 
Back
Top