PDA

View Full Version : Variables


ee99ee2
02-28-04, 10:36 PM
I'm new to C#, so go easy. :)

I've got a little script that I want to output text from a codebehind file. Here's my code:

Response.Write("myInt: $myint<br>");

$myint is set, and I just want to echo it's value. I'm coming from PHP, so help me out here. Doing the above just prints the text "myInt: $myint". I want $myint replaced with the var $myint.

I've also tried the following, but got an error about overloading:

Response.Write("myInt: {0}<br>", $myint);

I'm used to just typing echo "whatever I want to echo $var $var2". Is there a way to just use echo or print like I would in PHP in C#/ASP.NET?

-ee99ee

wtd
03-12-04, 12:13 AM
You'll need to read up on C# quite a bit more. This probably (untested) looks more like:

int myInt = 42;
Response.Write("myInt: " + myInt + "<br>");

Shane
03-23-04, 08:11 PM
I'm new to C#, so go easy. :)

I've got a little script that I want to output text from a codebehind file. Here's my code:

Response.Write("myInt: $myint<br>");

$myint is set, and I just want to echo it's value. I'm coming from PHP, so help me out here. Doing the above just prints the text "myInt: $myint". I want $myint replaced with the var $myint.

I've also tried the following, but got an error about overloading:

Response.Write("myInt: {0}<br>", $myint);

I'm used to just typing echo "whatever I want to echo $var $var2". Is there a way to just use echo or print like I would in PHP in C#/ASP.NET?

-ee99ee
Response.Write is bad. It's the "ok, it works, but it's not great" method.

Put a literal (<asp:literal id="ltlMessage" runat="server"/>) on your page and then use:

ltlMessage.Text = "myInt: " + myint.ToString() + "<br>";

to display it.