Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.
Here are some interesting situations that will raise compile time error:
string a = "Hello World"; 

for(int i=0;i<=10;i++) 
string b = "Hello World";
Both the if and the for loop will raise an error. That is because I have declared string 'a' and 'b' on the next line of both the statements without using the parenthesis. You should always include parenthesis even if your conditional statement consist of only one statement. Here is another situation:
string a += "Hello World";
The above statement will raise an error because string a has not been initialized. Now since a is a string should'nt this be assigned null and added to the "Hello World" string. The problem is that expression is evaluated from right to left and when it reaches the right side it finds something like this "Hello World" + a. Unfortunatly 'a' has not been defined yet and hence an error is raised. The line below will work fine.
string a = null; 
a += "Hello World";  // This will work fine
Posted on Sunday, July 24, 2005 10:58 PM | Back to top

Comments on this post: Playing with C# Expressions !

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Mohammad Azam | Powered by: