C#中怎么判断一维数组中的某些数值,是否包含一个数字

2025-03-19 00:04:48
推荐回答(4个)
回答(1):

int[] i = new int[] { 13,13,25,};
if (i.Contains(13))
{
    Console.WriteLine("包含!");
}

回答(2):

把数值转换成字符串,然后使用字符串替换函数

回答(3):

object[] newArray = new object[arrayList.length];
int index=0;
for(int i=0;i{
if(arrayList[i].ToString().IndexOf("3")<0)

{
newArray[index++] = arrayList[i];

}

}

回答(4):

public void doSth(int[] array,string s)
{
string temp;
foreach(int i in array)
{
temp=i.ToString()
if(temp.Contains(s))
{
temp.Replace(s,"")
i=Convert.ToInt32(temp);
}
}
}