急死我了,CSDN的高手呢?过星期天去了?????

phon 2004-11-21 03:33:28
一个ArrarList
我怎么知道他是否含有数库中的Name,如果有刚则删除。
也可看:
http://community.csdn.net/Expert/topic/3573/3573433.xml?temp=.1988031
...全文
98 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xaoxong 2004-11-21
  • 打赏
  • 举报
回复
同意: zpisgod(GOD) ( )
其实你也可另重新定义一个ArrayList把!="c"的Add到新的ArraryList
不过没有 zpisgod(GOD) ( ) 的简单些。
zpisgod 2004-11-21
  • 打赏
  • 举报
回复
呵呵,没有注意到吗? 那个i--, 就是让i自减一下
phon 2004-11-21
  • 打赏
  • 举报
回复
zpisgod(GOD) 你能不能说一下注意的那里应该做呀?
zpisgod 2004-11-21
  • 打赏
  • 举报
回复
很简单:

ArrayList myList=new ArrayList();
myList.Add("a");
myList.Add("b");
myList.Add("c");
myList.Add("c");
.
.
.

for(int i=0;i<myList.Count;i++)
{
if(myList[i].ToString()=="c")
{
myList.RemoveAt(i--); //注意这里就行了,删除一个myList.Count就减少了,所以让i-1;
}
}
qixiao 2004-11-21
  • 打赏
  • 举报
回复
那就加个redim ArrayList(length-1)
这个是vb中的不知道c#怎么写
你想一下数组的原理,定义的时候你个它指定了元素数,删除的时候并不能改变它的元素数

还有一个办法就是把数组弄到一个字符串里,操作之后再加进来
phon 2004-11-21
  • 打赏
  • 举报
回复
回复人: qixiao(七小) 删除一个另一个Index会变的。还不能达到目地呀。
listhome 2004-11-21
  • 打赏
  • 举报
回复
帮你查了一下MSDN
MS帮你写好了关于查找的方法IndexOf

下面是例子!

using System;
using System.Collections;
public class SamplesArrayList {

public static void Main() {

// Creates and initializes a new ArrayList with three elements of the same value.
ArrayList myAL = new ArrayList();
myAL.Add( "the" );
myAL.Add( "quick" );
myAL.Add( "brown" );
myAL.Add( "fox" );
myAL.Add( "jumps" );
myAL.Add( "over" );
myAL.Add( "the" );
myAL.Add( "lazy" );
myAL.Add( "dog" );
myAL.Add( "in" );
myAL.Add( "the" );
myAL.Add( "barn" );

// Displays the values of the ArrayList.
Console.WriteLine( "The ArrayList contains the following values:" );
PrintIndexAndValues( myAL );

// Search for the first occurrence of the duplicated value.
String myString = "the";
int myIndex = myAL.IndexOf( myString );
Console.WriteLine( "The first occurrence of \"{0}\" is at index {1}.", myString, myIndex );

// Search for the first occurrence of the duplicated value in the last section of the ArrayList.
myIndex = myAL.IndexOf( myString, 4 );
Console.WriteLine( "The first occurrence of \"{0}\" between index 4 and the end is at index {1}.", myString, myIndex );

// Search for the first occurrence of the duplicated value in a section of the ArrayList.
myIndex = myAL.IndexOf( myString, 6, 6 );
Console.WriteLine( "The first occurrence of \"{0}\" between index 6 and index 11 is at index {1}.", myString, myIndex );
}

public static void PrintIndexAndValues( IEnumerable myList ) {
int i = 0;
System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current );
Console.WriteLine();
}
}
qixiao 2004-11-21
  • 打赏
  • 举报
回复
先找到你要删除元素的index,然后用这个
ArrayList.Clear(ArrayList, index, length)
listhome 2004-11-21
  • 打赏
  • 举报
回复
你要删除重复的记录对吗???
phon 2004-11-21
  • 打赏
  • 举报
回复
急糊涂了, 是ArrayList

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧