Jump to content

Empty string: Difference between revisions

m
m (→‎Visual Basic .NET#In depth: Edited some more)
Line 2,276:
 
'#Object.Equals(Object, Object)
' First checks for reference equality and whether one or both of the arguments iis Nothing. It then invokes the
' instance Equals method of the left parameter.
P(Object.Equals(s, ""))
Line 2,291:
 
'#String.Length
' Check the Length property. The ?. (null-coalesceconditional) operator is used to avoid NullReferenceException. The Equals
' call above can also be done this way.
' A method call must be added because the equality operator propagates Nothing/null (that is, the result of the
Line 2,302:
 
'#String.Length
' A more traditional version of the null-coalesceconditional using a guard clause.
' Both the null-coalesceconditional and this are noticeably (~4 times) faster than "".Equals(s). In general, it appears that
' for empty strings, using the length is faster than using an equality comparison.
P(s IsNot Nothing AndAlso s.Length = 0)
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.