Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In PHP you can do this

 

$name = "Fredrik";

$var = "name";

echo ${$var};

 

and the output will be

 

Fredrik

 

Now I wonder if you can do somethins similar in C# or VB.NET?

 

---

Sassur

Posted

dim s as string= "John"

 

response.write (s)

Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Posted
dim s as string= "John"

 

response.write (s)

 

For a starter thats classic VB I asked about C# or VB.NET.

 

And thats not what I asked for.

 

I know how to define a variable and print it to the page.

Posted
Its almost exactly the same in C#.

 


string s = "John";

response.write (s); 

 

But as I said i the previous post, that isn't what I'm asking for.

 

Trying to explain better:

$name1 = "Fredrik";
$name2 = "Andreas";

$var = "name1";
echo $var . " = " . ${$var};
echo "<br>";

$var = "name2";
echo $var . " = " . ${$var};
echo "<br>";

 

and the output will be

 

 
name1 = Fredrik
name2 = Andreas

Posted

dim s1 as string = "jack"

dim s2 as string = "Daniels"

 

label1.text = "i drink " & s1 & " " & s2 & "<br>"

Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Posted
I am a little lost myself.
Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Posted

It look's more complicated then it is. The key to it is the variable $var

 

I will try to explane each line by it self

 

$name1 = "Fredrik";

initiates $name1 to Fredrik

 

$name2 = "Andreas";

initiates $name2 to Andreas

 

$var = "name1";

initiates $var to name1

 

echo $var . " = " . ${$var};

this will print :

name1 = Fredrik

 

take a look at ${$var}, that code means:

the variable with the name in variable $var

therefore

${$var} equels the variable $name1

 

echo "<br>";

prints "<br>"

 

$var = "name2";

set $var to name2

 

echo $var . " = " . ${$var};

name1 = Andreas

now the variable $var conatins name2

therefore

${$var} equels the variable $name2

 

echo "<br>";

prints "<br>"

 

Hoppes this makes it a little clearer.

  • Administrators
Posted

Not sure if you can do it exactly the way you say but you could achieve something similar with a collection.

 

	Dim vars As New Collections.Specialized.StringDictionary

	vars.Add("Name1", "Frederik")
	vars.Add("Name2", "Andreas")

	Dim name As String = "Name1"
	Response.writeline(vars(name)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
Not sure if you can do it exactly the way you say but you could achieve something similar with a collection.

 

	Dim vars As New Collections.Specialized.StringDictionary

	vars.Add("Name1", "Frederik")
	vars.Add("Name2", "Andreas")

	Dim name As String = "Name1"
	Response.writeline(vars(name)

 

Thanks, but not exactly that.

 

It seams that you cant use the Eval function to achieve what I want, but i havenät looked into it very deeply.

Posted

I don't see the use for what you're asking, seems to me like more memory consumption, if I want to copy the value of 1 variable into another variable I'll do something really simple

string name1 = "Superman";
string name2 = "Batman";

name1 = name2;

There you go, I assigned the value of the second variable into the first one, what's the result ? "BATMAN", why do things the hard way?????, this is exactly the same thing you're doing

Fat kids are harder to kidnap
Posted
I don't see the use for what you're asking, seems to me like more memory consumption, if I want to copy the value of 1 variable into another variable I'll do something really simple

string name1 = "Superman";
string name2 = "Batman";

name1 = name2;

There you go, I assigned the value of the second variable into the first one, what's the result ? "BATMAN", why do things the hard way?????, this is exactly the same thing you're doing

 

I think he's trying to print the actual name of the variable too. Thats the main difference.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...