
C#怎么删除数组中某列,
stringstrs="3,3,3;4,4,4;5,5,5";string[]points=newstring[]{};points=strs.Split(';');我想...
string strs= "3,3,3;4,4,4;5,5,5";
string[] points = new string[] { };
points = strs.Split(';');
我想删除数组中下标为1的列,请问怎么删除? 展开
string[] points = new string[] { };
points = strs.Split(';');
我想删除数组中下标为1的列,请问怎么删除? 展开
展开全部
数组的标识是从0开始的。如果你想删除3,3,3的话(此时的3,3,3的下标为0) 。
points .remove(0);就是删除下表为0的
points .remove(1);就是删除下表为1的,此时删除的是(4,4,4)
points .remove(0);就是删除下表为0的
points .remove(1);就是删除下表为1的,此时删除的是(4,4,4)
展开全部
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string strs = "3,3,3;4,4,4;5,5,5";
string[] points = new string[] { };
points = strs.Split(';');
string[] result = Remove(points, 1);
}
private static string[] Remove(string[] array, int index)
{
int length = array.Length;
string[] result = new string[length - 1];
Array.Copy(array, result, index);
Array.Copy(array, index + 1, result, index, length - index - 1);
return result;
}
}
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string strs = "3,3,3;4,4,4;5,5,5";
string[] points = new string[] { };
points = strs.Split(';');
string[] result = Remove(points, 1);
}
private static string[] Remove(string[] array, int index)
{
int length = array.Length;
string[] result = new string[length - 1];
Array.Copy(array, result, index);
Array.Copy(array, index + 1, result, index, length - index - 1);
return result;
}
}
}
追问
检举 | 2012-2-13 13:50 szchlaibin | 二级
or
private static string[] Remove(string[] array, int index)
{
int length = array.Length;
string[] result = new string[length - 1];
Array.Copy(array, result, index);
Array.Copy(array, index + 1, result, index, length - index - 1);
return result;
}
这个也不错
本回答被提问者采纳
展开全部
可以toarray,然后remove掉再转数组。也可以新建一个数组,挨个赋值。
追问
这数组都不是很会用,您能写个具体一点的吗?
追答
string strs = "3,3,3;4,4,4;5,5,5";
string[] points = new string[] { };
points = strs.Split(';');
List a = points.ToList();
a.RemoveAt(1);
string[] b = a.ToArray();
展开全部
string strs= "3,3,3;4,4,4;5,5,5";
string[] points = strs.Split(';');
points = points.Where(x=>x!="your value").ToArray();
string[] points = strs.Split(';');
points = points.Where(x=>x!="your value").ToArray();
展开全部
private static string[] Remove(string[] array, int index)
{
int length = array.Length;
string[] result = new string[length - 1];
Array.Copy(array, result, index);
Array.Copy(array, index + 1, result, index, length - index - 1);
return result;
}
看这段代码
{
int length = array.Length;
string[] result = new string[length - 1];
Array.Copy(array, result, index);
Array.Copy(array, index + 1, result, index, length - index - 1);
return result;
}
看这段代码
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询