Variable Scope Question
Variable Scope Question
(OP)
I'm banging my head against the wall trying to work this one out.
I have the code below:
and when I try and compile it, I get this error
Now I thought it was something to do with the scope of the baseVarElement variable within the curly braces so I made it the a method scope by changing the code to:
but I still get the same error.
Where am I going wrong?
I have the code below:
CODE --> c#
protected override void OnDragOver(DragEventArgs drgevent) { try { if (this.GetItem(position) != null) { BaseVar baseVarElement = this.GetItem(position); } else { BaseVar baseVarElement = this.GetGroup(position); } if (!object.ReferenceEquals(baseVarElement, this.PrevPosition)) { } } catch (Exception exception) { } }
Quote (Visual Studio)
A local variable named 'baseVarElement' cannot be declared in this scope because it would give a different meaning to 'baseVarElement', which is already used in a 'parent or current' scope to denote something else
Now I thought it was something to do with the scope of the baseVarElement variable within the curly braces so I made it the a method scope by changing the code to:
CODE --> c#
protected override void OnDragOver(DragEventArgs drgevent) { BaseVar baseVarElement; try { if (this.GetItem(position) != null) { BaseVar baseVarElement = this.GetItem(position); } else { BaseVar baseVarElement = this.GetGroup(position); } if (!object.ReferenceEquals(baseVarElement, this.PrevPosition)) { } } catch (Exception exception) { } }
Where am I going wrong?
All help is greatly appreciated
Kind regards
Ota
RE: Variable Scope Question
RE: Variable Scope Question
CODE
Borislav Borissov
VFP9 SP2, SQL Server