c# arraylist functions
中国IT站 www.chinaitz.com 2007-9-1
When you put then in the array list you could check to see if the item already exists. This code snippet will check to see if the string is already in the array and will only add it when the item doesn't already exist in the list.
static void Main( string[] args )
{
ArrayList list = new ArrayList();
AddToList( list, "Table1" );
AddToList( list, "Table4" );
AddToList( list, "Table1" );
AddToList( list, "Table3" );
AddToList( list, "Table2" );
AddToList( list, "Table2" );
foreach ( string s in list ) //this will loop the collection to show there are no duplicates
{
Console.WriteLine( s );
}
}
private static void AddToList( ArrayList list, string p )
{
if ( list.Contains( p ) == false )
list.Add( p );
}
9995
评论加载中...相关资讯
- 2007-9-14C#编码好习惯
- 2007-9-14C#中的抽象类
- 2007-9-14解读 C# 中的正则表达式
- 2007-9-14Visual C# 诠释常用排序算法
- 2007-9-14C#箴言:使用构造函数初始化语句
- 2007-9-14C#箴言:用静态构造函数初始化静态成员
- 2007-9-14C#中ref和out的使用小结
- 2007-9-14DotNet(C#)学习-你学到什么程度!
- 2007-9-14C#3.0新特性之隐式类型局部变量的使用
- 2007-9-14Visual C# 2005快速入门之编写方法
