// Use a strongly typed System.Int32 to iterate over contents.
foreach (int item in evenNumbers)
{
Console.WriteLine("Item value: {0}", item);
}
}
Restrictions on Implicitly Typed Variables
There are, of course, various restrictions regarding the use of the var keyword. First and foremost,
implicit typing applies only to local variables in a method or property scope. It is illegal to use the
var keyword to define return values, parameters, or field data of a type:
class ThisWillNeverCompile
{
// Error! var cannot be used as field data!
private var myInt = 10;
C H A P T E R 1 3
■
C # 2 0 0 8 L A N G U A G E F E AT U R E S
417
8849CH13.qxd 10/2/07 12:42 PM Page 417
Do'stlaringiz bilan baham: |