c# - Bang vs Default Property in Visual Basic -
for given class, default property of list, can access instance object in list doing myclass.defproperty("key"). can achieve same results typing myclass.defproperty!key.
i have been told using parenthesis , quotes faster way runtime accesses property, i'd understand difference , how each work...
i understand c# has similar behavior replacing parenthesis square brackets.
given following code in visual basic.net:
dim x new dictionary(of string, string) x.item("foo") = "bar"
you can access "foo" member of dictionary using of following:
dim = x!foo dim b = x("foo") dim c = x.item("foo")
if @ il under reflector.net you'll find translate to:
dim string = x.item("foo") dim b string = x.item("foo") dim c string = x.item("foo")
so, equivalent in il and, of course, execute @ same speed.
the bang operator lets use statically defined keys conform standard variable naming rules.
using indexed approaches keys can valid value (in case string) , can use variables represent key.
for code readability recommend x.item("foo")
notation is clear going on. x("foo")
can confused call procedure , x!foo
makes foo
variable , not string (which is). stack overflow color-coding makes foo
keyword!
the c# equivalent code x["foo"];
. there no !
syntax equivalent.
so, bottom-line !
isn't better or worse on performance , may make code maintenance more difficult should avoided.
Comments
Post a Comment