vb.net - VB setting a string to nothing -


the code below returns true when expected return false.

why return true? expect nothing set value of string null, not empty (according msdn)

codeingground sample

module vbmodule      sub main()         dim x string         x = nothing         console.writeline(x = string.empty)     end sub  end module 

nothing (visual basic)

represents default value of data type. reference types, default value null reference.

***edit**** nothing = string.empty (why these equal?)

nothing in vb.net default value type. language spec says in section 2.4.7:

nothing special literal; not have type , convertible types in type system, including type parameters. when converted particular type, equivalent of default value of type.

so, when test against string.empty, nothing converted string, has length 0. operator should used testing against nothing, , string.empty.equals(nothing) return false.

per comment,

when converted particular type, equivalent of default value of type.

the default value string null. dont understand why answer accepted.

difference between c# , vb.net string comparison

the above post explains answer clearly, credit goes tim schmelter in comment section finding above post

per tim schmeleters comments

it called vb compiler documentation states in string.equality operator


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -