我是C#的新手,想知道C#中是否存在类似私有继承的东西(比如在C++中)?
我的问题如下:我想实现一个队列(将其命名为SpecialQueue),并进行以下更改:
在c ++中,我会从队列中私有ihnerit,只暴露我想要的方法,并根据我的意愿改变其他方法.但不幸的是,队列中的所有方法都没有"覆盖"修饰符,我不知道如何在C#中实现它.
有帮助吗?
问候,丹
我需要实现一个具有特殊功能的集合。另外,我想将此集合绑定到 ListView,因此我最终得到了下一个代码(我在论坛中省略了一些使其更短的方法):
public class myCollection<T> : INotifyCollectionChanged
{
private Collection<T> collection = new Collection<T>();
public event NotifyCollectionChangedEventHandler CollectionChanged;
public void Add(T item)
{
collection.Insert(collection.Count, item);
OnCollectionChange(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
}
protected virtual void OnCollectionChange(NotifyCollectionChangedEventArgs e)
{
if (CollectionChanged != null)
CollectionChanged(this, e);
}
}
Run Code Online (Sandbox Code Playgroud)
我想用一个简单的数据类来测试它:
public class Person
{
public string GivenName { get; set; }
public string SurName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
所以我创建了 myCollection 类的实例,如下所示:
myCollection<Person> _PersonCollection = new myCollection<Person>();
public myCollection<Person> PersonCollection
{ get { return _PersonCollection; } …Run Code Online (Sandbox Code Playgroud) data-binding wpf observablecollection inotifycollectionchanged