c# arraylist functions _c#应用

2008-02-23 05:45:28来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

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 doesnt 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 );
}



标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: 在c#里使用using操作符_c#应用

下一篇: c# source 和vb source 的不同_c#应用