Q:

Autoincrement won't work inside foreach in a table

Right now I'm trying to add a feature to my table. 
It's being done inside a cshtml C# MVC ASP.NET Enviroment. 
@{
    dt_Table = ds_Set. Tables[1];
    foreach (System. Data. DataRow dr in dt_Table. Rows)
    {
        int autoincrement = 0;
        string nombre = dr["Nombre"].ToString();

        <tr>
            <td align="center">@(autoincrement++)</td>
            <td align="center">@nombre</td>
        </tr>

    }
}

How do I add auto increment or ++ to the value? 
Right now like that it just prints "1" on each row of the table :(
How can I solve this? 

A:

The variable autoincrement is scoped to the foreach loop block so it is allocated and released each iteration.   Declare the variable outside of the foreach loop (or you can use a for loop):
for( var i = 0; i < dt_Table. Rows. Count; ++i )
{
    var dr = dt_Table. Rows[i];
    var nombre = dr["Nombre"].ToString();

    <tr>
        <td align="center">@i</td>
        <td align="center">@nombre</td>
    </tr>
}

