CollectionBase.InnerList 属性

本文介绍了一个基于C#的CollectionBase类的简单实现,通过继承CollectionBase并利用其InnerList属性来快速实现集合的基本增删查操作。示例代码展示了如何添加、删除元素以及清空集合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

获取一个 ArrayList,它包含 CollectionBase 实例中元素的列表。

 

语法:

 

protected ArrayList InnerList { get; }

属性值

类型:System.Collections..::.ArrayList

表示 CollectionBase 实例本身的 ArrayList

 

示例:(摘自《Data Structures and Algorithms Using C#》)

 

using System;
using System.Collections;
public class Collection : CollectionBase<T> {
public void Add(Object item) {
InnerList.Add(item);
}
public void Remove(Object item) {
InnerList.Remove(item);
}
public new void Clear() {
InnerList.Clear();
}
public new int Count() {
return InnerList.Count;
}
}
class chapter1 {

static void Main() {
Collection names = new Collection();
names.Add("David");
names.Add("Bernica");
names.Add("Raymond");
names.Add("Clayton");
foreach (Object name in names)
Console.WriteLine(name);
Console.WriteLine("Number of names: " + names.
Count());
names.Remove("Raymond");
Console.WriteLine("Number of names: " + names.
Count());
names.Clear();
Console.WriteLine("Number of names: " + names.
Count());
}
}

System.NotSupportedException HResult=0x80131515 Message=此方法显式使用的 CAS 策略已被 .NET Framework 弃用。若要出于兼容性原因而启用 CAS 策略,请使用 NetFx40_LegacySecurityPolicy 配置开关。有关详细信息,请参见 http://go.microsoft.com/fwlink/?LinkID=155570。 Source=mscorlib StackTrace: 在 System.Security.SecurityManager.ResolvePolicy(Evidence evidence) 在 DevExpress.Data.Helpers.SecurityHelper.IsPermissionGranted(IPermission permission) 在 DevExpress.Data.Helpers.SecurityHelper.get_IsPartialTrust() 在 DevExpress.Data.Helpers.DataViewDataControllerHelper.InitFastGetRow() 在 DevExpress.Data.Helpers.DataViewDataControllerHelper..ctor(DataControllerBase controller) 在 DevExpress.Data.DataControllerBase.CreateHelper() 在 DevExpress.Data.DataControllerBase.OnListSourceChanged() 在 DevExpress.Data.DataControllerBase.SetListSourceCore(IList value) 在 DevExpress.Data.DataControllerBase.SetListSource(IList value) 在 DevExpress.Data.CurrencyDataController.OnCurrencyManagerChanged() 在 DevExpress.Data.CurrencyDataController.set_CurrencyManager(CurrencyManager value) 在 DevExpress.Data.CurrencyDataController.OnDataSourceChanged() 在 DevExpress.Data.CurrencyDataController.SetDataSource(BindingContext context, Object dataSource, String dataMember) 在 DevExpress.XtraGrid.Views.Base.BaseView.SetDataSource(BindingContext context, Object dataSource, String dataMember) 在 DevExpress.XtraGrid.GridControl.ActivateDataSource() 在 DevExpress.XtraGrid.GridControl.set_DataSource(Object value) 在 ScadaIvGraphicEdit.EditForm.ReadLayerSetting() 在 D:\UGit\utdrawtool\drawtool-dotnet2.0\图形平台\ScadaIvGraphicEdit\ScadaIvGraphicEdit\EditForm.cs 中: 第 12926 行 在 ScadaIvGraphicEdit.EditForm.xtraTabControl_SelectedPageChanged(Object sender, TabPageChangedEventArgs e) 在 D:\UGit\utdrawtool\drawtool-dotnet2.0\图形平台\ScadaIvGraphicEdit\ScadaIvGraphicEdit\EditForm.cs 中: 第 7603 行 在 DevExpress.XtraTab.XtraTabControl.OnSelectedPageChanged(Object sender, ViewInfoTabPageChangedEventArgs e) 在 DevExpress.XtraTab.ViewInfo.BaseTabControlViewInfo.OnSelectedPageChanged(IXtraTabPage prevPage) 在 DevExpress.XtraTab.ViewInfo.BaseTabControlViewInfo.set_SelectedTabPage(IXtraTabPage value) 在 DevExpress.XtraTab.ViewInfo.BaseTabControlViewInfo.OnPageAdded(IXtraTabPage page) 在 DevExpress.XtraTab.XtraTabControl.OnTabPageAdded(XtraTabPage page) 在 DevExpress.XtraTab.XtraTabControl.OnTagPagesCollectionChanged(Object sender, CollectionChangeEventArgs e) 在 DevExpress.XtraTab.XtraTabPageCollection.RaiseCollectionChanged(CollectionChangeEventArgs e) 在 DevExpress.XtraTab.XtraTabPageCollection.OnInsertComplete(Int32 position, Object value) 在 System.Collections.CollectionBase.System.Collections.IList.Add(Object value)
最新发布
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值