|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How can I create a Dynamic variable in .NET?
HI, How can I create a Dynamic variable in .NET?
For instance, I need to create a dynamic variable imagine the following code: Dim var1 as String ="Test" Imagine that the variable "var1" doesn't exit and I need create it without declared nothing, where everything was Dynamic, For example I Wouldn't this declaration "Dim var1 as String" . For example, I would need something like it: I need create a specific method like it: newmethod (newvariable,value) For example: newmethod ("var1","Test") imagine it would be possible too: newmethod ("var2",var1) and it too: newmethod ("var3",var2) So, Imagine When I Wanted to get the value I used a another method like this: evaluate(var1) response.write (evaluate(var1)) Display: Test evaluate(var2) response.write (evaluate(var2)) Display: Test Please I Need your help about it. |
|
#2
|
|||
|
|||
|
If you are only dealing with strings, or items that can be used as strings, you could try using a hashtable.
'-- declare Dim myHash As Hashtable = New Hashtable(100) '-- initialize with 100, though it will resize automatically '-- add myHash.Add("var1", "the value") '-- see if it exists If myHash.Contains("var1") Then ... End If '-- get the value Dim myString = myHash("var1") Remember though, that the key (var1 in this example) has to be unique. Its always a good idea to check to see if the key exists before you try creating a new entry to ensure you aren't going to try using a key thats's already been defined. |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > How can I create a Dynamic variable in .NET? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|