M
mp
in vb6
Dim o As Object
If o Is Nothing Then
in C# ???
Object o;
If (o == null)
{}
is that correct?
Dim o As Object
If o Is Nothing Then
in C# ???
Object o;
If (o == null)
{}
is that correct?
Steel said:If the object = null, then it doesn't exist.
Peter Duniho said:Yes, that is correct.
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