c# - Why does vb.net allow class names to be parameter names? -
i have seen sub
looked this:
private sub dosomething(byref placeholder placeholder) 'do placeholder object end sub
i wonder why allowed. can name few languages not allowed. able have methods same return, parameters , names if 1 of them shared
, other instance-level.
for example, let suppose there class
named bird
, there object this
dim bird = new bird("duck doggers")
bird.fly()
make sure duck doggers flies, however, bird.fly()
make birds fly, if, instance ienumerable
updated upon each constructor run of bird
, bird.fly
iterate ienumerable
, call fly
each item. far can see, impossible in vb.net, since fly either shared
or instance-level. there possible problem (besides unclarity) if parameter name same class
name instance said parameter?
i not have c# in front of me, wonder whether naming of parameter class
possible there.
this common naming pattern majority of vb developers. of stems vb being case-insensitive. without being allowed name variables way, either variable, or class name have renamed "creatively" avoid conflicts, leads things hungarian notation, or other strange naming patterns. while may odd isn't used it, becomes 2nd nature vb developer. calling shared
member on instance variable "passes though" shared member, in following example.
public class bird public shared sub fly debug.writeline("fly called shared") end sub public sub quack debug.writeline("quack called instance") end sub end class public class main public sub test(bird bird) bird.fly() bird.fly() bird.quack() bird.quack() end sub end class
calling test
results in following output.
fly called shared
fly called shared
quack called instance
quack called instance
Comments
Post a Comment