.Net class inheritance
Ok, here is what I am trying to do, I want to write a class that inherits everything from the ListItem class
class RealListItem : ListItem
{
public string anExtraStringINeed;
}
For one reason or another .net treats all members as if they are private when I try to do this, which is why my class is useless.
I tried to make it work and do it like this:
class RealListItem : ListItem
{
public string anExtraStringINeed;
public ListItem list;
}
but it still doesn't work because I need to use it in a function that uses the ListItem accepts type and RealListItem doesn't play well as it should. I can make aRealListItem.list, but this only passes the list from the RealListItem I need the whole object to pass.
What am I doing wrong with this or is Microsoft just not letting you inherit from .net classes?
As Charles states, the ListItem is sealed, which means you cannot inherit from it. Within the framework, some classes are marked as sealed while others are not. (Those that are not sealed, you can inherit.)
You can create your own ListItem containing System.Web.UI.WebControls.ListItem, but I don't think that will really provide you much benefit.
What are you trying to achieve? You may need to find an alternative way to do things.
source to share