Search code examples
c#visual-studio-2003datarow

vs2003: identify first row in DataRow[]


what is the best way to identify first row in the following code?

foreach(DataRow row in myrows)
{

if (first row )
{
...do this...
}
else
{
....process other than first rows..
}
}

Solution

  • You can use a boolean flag for this:

    bool isFirst = true;
    
    foreach(DataRow row in myrows)
    {
        if (isFirst)
        {
            isFirst = false;
            ...do this...
        }
        else
        {
            ....process other than first rows..
        }
    }