C# is not recognizing var “datatype”
if (e.Row.RowType == DataControlRowType.DataRow)
{
var lblNewsal = e.Row.FindControl("lblSalary") as Label;
if (lblNewsal != null)
{
Total += int.Parse(lblNewsal.Text);
}
}
Error is:
Error 1 The type or namespace name ‘var’ could not be found (are you
missing a using directive or an assembly reference?)
G:\ControlsExample\GridViewDemo\Default.aspx.cs 31 14
G:\ControlsExample\GridViewDemo\
The
varkeyword was introduced to C# 3.0 (Visual Studio 2008+), so cannot be used for .NET 2.0 and before (so anything before Visual Studio 2005 will not have support for it).You need to either use the explicit type in that line:
Or upgrade.