You can store the previous value on each iteration of the loop to use in the next iteration.
var prev = 0;
foreach (DataRow row in dt.Rows)
{
var quote = Convert.ToDouble(row["Data"]) - Convert.ToDouble(prev);
prev = row["Data"];
}
How to set quote with an initial value of 0:
double quote = 0.0;
var prev = 0;
foreach (DataRow row in dt.Rows)
{
quote = Convert.ToDouble(row["Data"]) - Convert.ToDouble(prev);
prev = row["Data"];
}
Another way to set quote to 0 on the first iteration of the loop:
var prev = 0;
var i = 0;
foreach (DataRow row in dt.Rows)
{
double quote;
if(i == 0)
{
quote = 0.0;
}
else
{
quote = Convert.ToDouble(row["Data"]) - Convert.ToDouble(prev);
}
prev = row["Data"];
i++;
}
NOTE: this last example, based on OP's comments to my answer, is really just a stab in the dark because the OP has given no clear definition of what is needed. These add-on examples are really beyond the scope of the original question.