Re: Assigning a 'type' to a variable at runtime
- From: "Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx>
- Date: Tue, 11 Oct 2005 09:23:18 +0200
JohnR,
We see this more in this newsgroup and than I think forever, what will be
the use of this solution. It sounds for me as throwing apples and pears in
one container and than split them again afterwards. Why not direct in two
containers. That will probably keep the taste of the apples and the pears
much better.
Can you explain to us what is your reason behind this question?
(That container withouth telling what it is, is of couse 'object').
Cor
"JohnR" <JohnR104@xxxxxxxxxxx> schreef in bericht
news:RqH2f.9102$tU1.1605@xxxxxxxxxxx
> I'm trying to find a way to create a variable of a given type at runtime
> where I won't know the type until it actually executes. For example,
>
> dim x as object = "hi"
>
> x is declared as an object but x.gettype returns 'string', so it knows it
> contains a string.
>
> If I want to create a variable "y" as the same type that variable x
> contains how would I do that without having to iterate thru every possible
> type? That is, for the above example I would want the equivalent of "dim
> y as string" because x.gettype is string. Another example:
>
> dim x as object = new MyClass
>
> x.gettype would return 'MyClass' so I would want the equivalent of "dim y
> as myclass".
>
> Although it's not legal to do this "Dim y as x.gettype.name" that is
> exactly what I want to do.
>
> Is there anyway to accomplish this?
>
> Thanks, John
>
.
- References:
- Assigning a 'type' to a variable at runtime
- From: JohnR
- Assigning a 'type' to a variable at runtime
- Prev by Date: Re: ListBox SelectionMode
- Next by Date: Re: readonly wrapper for a collection
- Previous by thread: Re: Assigning a 'type' to a variable at runtime
- Next by thread: Re: Assigning a 'type' to a variable at runtime
- Index(es):
Relevant Pages
|