首页  编辑  

删除ArrayList中重复的值

Tags: /C#/其他技巧/   Date Created:

ArrayList vArrayList = new ArrayList ();

Random vRandom = new Random ();

for ( int i = 0 ; i < 100 ; i ++ )

   vArrayList . Add(vRandom . Next( 100 ));

for ( int i = vArrayList . Count - 1 ; i >= 0 ; i -- )

    if (vArrayList . IndexOf(vArrayList[i]) != i)

       vArrayList . RemoveAt(i);

vArrayList . Sort();

for ( int i = 0 ; i < vArrayList . Count; i ++ )

   listBox1 . Items . Add(vArrayList[i]);