Reputation: 2051
I try to use overriding in Ranorex Studio (c# language using)
public class DropListActions
{
public void SimpleSelectByInnerText(string text, bool close){
}
}
public class CheckBoxDropListWithInputField : DropListActions
{
//overriding
public void SimpleSelectByInnerText(string text, bool close){
}
}
all works well, but in the report showed warnings:
'****************.CheckBoxDropListWithInputField.SimpleSelectByInnerText(string, bool)' hides inherited member '****************.DropListActions.SimpleSelectByInnerText(string, bool)'. Use the new keyword if hiding was intended. (CS0108) - C:\*****\\Ranorex\RanorexStudio Projects\*****\DropListActions.cs:117,18
For example in java
all overriding methods marked by @Override
annotation. Maybe in c#
there exists an appropriate way to do this? How to skip those warnings messages?
Upvotes: 1
Views: 492
Reputation: 16711
Both the base class and the derived class have a method with the same name (SimpleSelectByInnerText
). The compiler is telling you that the method in the derived class is "hiding" the method in the base class (you're not overriding it because only virtual
or abstract
methods can be overridden).
To get rid of this warning you can use the new
keyword which tells the compiler that you intend to "hide" the base method:
public class CheckBoxDropListWithInputField : DropListActions
{
public new void SimpleSelectByInnerText(string text, bool close)
{ // ^ new keyword here before the return type
}
}
Alternatively, you could use override
and mark the method in the base class as virtual
:
public class DropListActions
{
public virtual void SimpleSelectByInnerText(string text, bool close)
{
}
}
public class CheckBoxDropListWithInputField : DropListActions
{
public override void SimpleSelectByInnerText(string text, bool close)
{
}
}
See What’s the difference between override and new? by Jon Skeet and Compiler Warning (level 2) CS0108 for more info.
Upvotes: 1