473,382 Members | 1,093 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

The keyword new is required on 'B.IsValid' because it hides inherited member 'A.IsValid'

The keyword new is required on 'B.IsValid' because it hides inherited member
'A.IsValid'
All I have a couple of classes which resemble (sort of!) this:

public class A
{
public bool bIsValid = true;

public bool IsValid
{
get{ return bIsValid; }
}
}
public class B : A
{
public bool bIsValid = false

public bool IsValid
{
get{ return bIsValid; }
}
}

Now whenever I call IsValid on an object of type A I always want to get
"true" returned, and likewise for an object of type B I always want to get
"false" returned.

How can I acheive this and get rid of this warning at the same time?

Thanks
MA
Nov 16 '05 #1
2 6056
"Paul Tomlinson" <ru************@hotmail.com> wrote in message
news:eD**************@TK2MSFTNGP15.phx.gbl...
The keyword new is required on 'B.IsValid' because it hides inherited
member 'A.IsValid'
All I have a couple of classes which resemble (sort of!) this:

public class A
{
public bool bIsValid = true;

public bool IsValid
{
get{ return bIsValid; }
}
}
public class B : A
{
public bool bIsValid = false

public bool IsValid
{
get{ return bIsValid; }
}
}

Now whenever I call IsValid on an object of type A I always want to get
"true" returned, and likewise for an object of type B I always want to get
"false" returned.

How can I acheive this and get rid of this warning at the same time?

Thanks
MA


This is basic inheritence, so you need to "override" the IsValid method
defined in class A in class B if you want it to act differently in the
inherited class, e.g:

public class A
{
public bool IsValid
{
get { return true; }
}
}

public class B : A
{
public override bool IsValid
{
get { return false; }
}
}
Nov 16 '05 #2
"Jako Menkveld" <ja***********@envalue.ch> wrote in message
news:uF*************@TK2MSFTNGP10.phx.gbl...
"Paul Tomlinson" <ru************@hotmail.com> wrote in message
news:eD**************@TK2MSFTNGP15.phx.gbl...
The keyword new is required on 'B.IsValid' because it hides inherited
member 'A.IsValid'
All I have a couple of classes which resemble (sort of!) this:

public class A
{
public bool bIsValid = true;

public bool IsValid
{
get{ return bIsValid; }
}
}
public class B : A
{
public bool bIsValid = false

public bool IsValid
{
get{ return bIsValid; }
}
}

Now whenever I call IsValid on an object of type A I always want to get
"true" returned, and likewise for an object of type B I always want to
get "false" returned.

How can I acheive this and get rid of this warning at the same time?

Thanks
MA


This is basic inheritence, so you need to "override" the IsValid method
defined in class A in class B if you want it to act differently in the
inherited class, e.g:

public class A
{
public bool IsValid
{
get { return true; }
}
}

public class B : A
{
public override bool IsValid
{
get { return false; }
}
}


Oh, just remembered, you have to mark A.IsValid as virtual, otherwise you
will get a compiler error:

e.g. In class A
public virtual bool IsValid
{
....
}

The virtual keyword tells the compiler that the method can be overriden by
subclasses.
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Daniel Barna | last post by:
Hi I am a bit confused. I thought always that if a class inherits from another (public), then all of its base class's public member function are also visible in this class - even if it declares a...
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
3
by: Danny Din | last post by:
Hi, I have the following code – public class Class1 { public Class1()
3
by: Wayne Brantley | last post by:
VS2005 RTM Create a web user control to use as a base class for other web user controls. Now, create a new web user control, change the class it inherits from to your base class and compile....
2
by: Walt Zydhek | last post by:
Could someone tell me how to Change the parameter type for an override of an inherited class member? In particular, I would like to change an indexer for my class that implements the IList class....
0
by: source | last post by:
I am tyring to get inhertied members of a type using relfection, but i am not able to do it. What bindingflags do I need to use to get inhertied members. Any pointers will help source
4
by: Alan T | last post by:
I got a method in my ancestor form declared as Protected, this method has empty body. In my descendant form I declared as Protected also, then compile has no problem but the name of the method has...
1
by: Dinis Correia | last post by:
Hi all, How can I replace an inherited member name? I've built a class that inherits from KeyedCollection(Of ..., ...). I would like to replace base class Items property with Fields property. Is...
5
by: Anders Borum | last post by:
Hello I'm developing an API with a number of concrete collections that inherit from an abstract collection hierarchy. Each inheritance level provides an implementation of IEnumerable<T>, thus...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.