Error10A local variable named 'dAdd' cannot be declared in this scope because it would give a different meaning to 'dAdd', which is already used in a 'parent or current' scope to denote something elseE:\MY PROJECT\16-11-2013\UNIVERSAL ENTERPRISES\Universal.cs\frmInvoiceDetails.cs16726MAYUR.cs
Loading
VulpesPosted Nov 18, 2013, 10:04 AM
void SomeMethod()
{
DateTime dAdd = DateTime.Today;
while(condition)
{
DateTime dAdd; // not allowed
// do something with dAdd
}
}
Here, you're not allowed to declare a local variable called dAdd in the while loop because there's already a local variable called dAdd declared outside the loop.
The reason why this isn't allowed is because, otherwise, there would be no way to access the 'outer' variable from within the loop.
To remedy the situation, either:
1. Change the name of the variable in the while loop.
2. Use the 'outer' variable instead if that's in fact what you intended to do all along.