html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

c# arraylist functions_.NET教程_编程技术

[ ] 已经帮助:人解决问题

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

rRmHTML5中文学习网 - HTML5先行者学习网
rRmHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助