Answer: No, var keyword is used to declare implicitly typed local variable. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type.
So you can declare a local variable of any type using
var keyword but you can't declare an array of variable using var keyword.
Correct
string[] str = { "ram", "sham" };
foreach (var s in str)
{
Response.Write(s + "<br />");
}
Wrong
var[] str = { "ram", "sham" };
foreach (var s in str)
{
Response.Write(s + "<br />");
}
This will throw "
CS0246: The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?) " error.
For more info on var keyword see
http://msdn.microsoft.com/en-us/library/bb383973.aspx
Thanks
Asked In: Many Interviews |
Alert Moderator