Deze post is geïmporteerd van de oude blog en is nog niet geconverteerd naar de nieuwe syntax.
In response to a thread on the ASP.NET Forums I decided to publish the answers in an overview on my blog.
Someone asked on what the difference were between PHP and ASP.NET and how he did certain things.
My answers are based on using C# as the language for your ASP.NET application.
__________________________________
1. Is there any difference between '' and "" in ASP.NET?
Yes, ' ' is used for characters while " " is for strings.
Take this for example:
'a' = a in memory
"a" = a and \0 in memory
Something useful about escaping in ASP.NET is the following:
@"bla\bla" == "bla\\bla"
A string with an @ in front of it is seen as a literal, where you don't have to escape special characters.
2. How would I do something like: print $variable.'string'; in ASP.NET?
You would use the following: Response.Write(variable + "string");
But it isn't very recommended to use Response.Write, take a look at all the server controls you have, like a Label for example.
3. Within an if language construct, what would be the equivalent of "and" and "or?"
Actually PHP supports the same being used in ASP.NET:
and --> &&
or --> ||
Example:
[csharp]
if (((number == 5) && (number2 != 8)) || (admin == true)) {
// do stuff
}
[/csharp]
Would correspond to:
if (number = 5 AND number2 NOT equal to 8 ) OR we're an admin., do stuff.
4. Would someone be able to tell me how I could make an ASP.NET equivalent of this PHP Function:
[php]
function num($number){
return '#' . str_pad($number, 3, '0', STR_PAD_LEFT);
}
[/php]
You need a function which returns a string, and which formats a string:
[csharp]
public string num(int number) {
return String.Format("#{0}", number.ToString("000"));
}
[/csharp]
5. How do I create a mutidimensional array?
Try this:
[csharp]
// 2 dimensional arrays
int [,] a1;
a1 = new int[3,2];
int [,] a2 = {{1,2}, {3,4}, {5,6}};
// jagged arrays
int[][] a3;
a3 = new int[3][];
a3[0] = new int[5]{1, 2, 3, 4 ,5};
a3[1] = new int[3];
a3[2] = new int[4]{21, 22, 23, 24};
[/csharp]
Loop over them to see the elements.
__________________________________
Got a question yourself? Ask it, and I'll try to help :)
Someone asked on what the difference were between PHP and ASP.NET and how he did certain things.
My answers are based on using C# as the language for your ASP.NET application.
__________________________________
1. Is there any difference between '' and "" in ASP.NET?
Yes, ' ' is used for characters while " " is for strings.
Take this for example:
'a' = a in memory
"a" = a and \0 in memory
Something useful about escaping in ASP.NET is the following:
@"bla\bla" == "bla\\bla"
A string with an @ in front of it is seen as a literal, where you don't have to escape special characters.
2. How would I do something like: print $variable.'string'; in ASP.NET?
You would use the following: Response.Write(variable + "string");
But it isn't very recommended to use Response.Write, take a look at all the server controls you have, like a Label for example.
3. Within an if language construct, what would be the equivalent of "and" and "or?"
Actually PHP supports the same being used in ASP.NET:
and --> &&
or --> ||
Example:
[csharp]
if (((number == 5) && (number2 != 8)) || (admin == true)) {
// do stuff
}
[/csharp]
Would correspond to:
if (number = 5 AND number2 NOT equal to 8 ) OR we're an admin., do stuff.
4. Would someone be able to tell me how I could make an ASP.NET equivalent of this PHP Function:
[php]
function num($number){
return '#' . str_pad($number, 3, '0', STR_PAD_LEFT);
}
[/php]
You need a function which returns a string, and which formats a string:
[csharp]
public string num(int number) {
return String.Format("#{0}", number.ToString("000"));
}
[/csharp]
5. How do I create a mutidimensional array?
Try this:
[csharp]
// 2 dimensional arrays
int [,] a1;
a1 = new int[3,2];
int [,] a2 = {{1,2}, {3,4}, {5,6}};
// jagged arrays
int[][] a3;
a3 = new int[3][];
a3[0] = new int[5]{1, 2, 3, 4 ,5};
a3[1] = new int[3];
a3[2] = new int[4]{21, 22, 23, 24};
[/csharp]
Loop over them to see the elements.
__________________________________
Got a question yourself? Ask it, and I'll try to help :)