Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am getting error at protected override int RowCount()
{ } like no suitable method found to override.

What I have tried:

I have two projects in sln
In X project --> class is X1:Method is like.
protected override int RowCount()
{
logic......
return Count;
}

In Y project --> class is Y1

protected virtual int RowCount()
{
return -1;
}

Private void xx()
{
Count = RowCount();
}


I have added references also,please help me how to avoid error.
Posted
Updated 18-Jul-18 19:49pm

1 solution

You can only override methods in classes that are derived from the original: so unless X1 is derived from Y1 you cannot override it's methods.
public class X1 : Y1
    {
    protected override int RowCount()
        {
        return Count;
        }
    }

public class Y1
    {
    protected int Count = 666;
    protected virtual int RowCount()
        {
        return -1;
        }
    }
Will work.
 
Share this answer
 
Comments
Dave Kreskowiak 19-Jul-18 10:07am    
I've no idea why you got 1-voted. It's a perfectly reasonable answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900