Re: dynamic typing by Rob
Rob
Thu Jul 24 15:59:05 CDT 2003
Just Dim the variable as Object. All classes inherit from Object, so a
variable that is a reference to Object can be assigned to any class
instance.
Dim ctrl As Object
ctrl = AnyObjectYouWant
If you want to be more specific, you use another subclass that all your
objects have in common. That gives you an added measure of type safety. So,
for example, if this variable only ever uses objects that are derived from
the Control class, you can Dim the variable as Control.
Dim ctrl As Control
ctrl = AnyControlObjectYouWant
In this case, you can't assign a non-control object to the variable, so you
get better protection and intellisense.
-Rob [MVP]
"mahmut arslan" <mahar@kocbank.com.tr> wrote in message
news:05eb01c351b0$991b6830$a601280a@phx.gbl...
> is it possible in VB.NET to declare a variable whose type
> will be clear in runtime e.g.
>
> dim ctrl as LinkButton
> dim tp as Type = Type.GetType(Control)
> dim ctrl_dynamic as tp
>
> or something like this.
> (I know, the code above is not working)
>