Wednesday, February 16, 2005
Why do we have 2 Comaprison Operators in VB ?
the 2 comparison operators i am talking about here are : "Is" and "="
actually , the existence of both of them returns to the old VB6 . coz for old classes we used to have 3 property accessors : "Let , get and set " and the old mistake "default properties "
so we can say simply in VB6 :
Label1 = "User Name : " which means Let Label1 = "User Name : "
and we can also say
Label1 = new Label() which means Set Label1 = new label()
so in the past if we say :
if label1 = "User name" then 'do something this is a using of the opreator "="
but if we say if Label1 = label2 then 'do something this invokes the "Is" operator .
we no more have "set" in VB.NET , so some people think "Is" should have been removed from the language as well and have only 1 comparison .
but it is due to simplicity and more readability (from my point of view) that they still keep the "Is" so we still have reference comaprison as well as value comparison or else we are going to write it as the other languages Object.ReferenceEquals(a,b) . so using "Is" is much more readable and cleaner ..