using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Diagnostics;
namespace testconsole
{
class Class1
{
static void Main()
{
string[] strArrs = new string[] { "1", "1", "1", "7", "6", "4" };
List<string> listArrs = GetNewArrs(strArrs, "7");
foreach (string str in listArrs)
{
Console.WriteLine(str);
} Console.WriteLine("\n\n");
int index = GetIndex(strArrs, "7");
string[] strArrs2 = GetNewArrs(strArrs, index);
foreach (string str in strArrs2)
{
Console.WriteLine(str);
}
Console.ReadKey();
} static List<string> GetNewArrs(string[] strArrs, string strValue)
{
List<string> strNewArrs = new List<string>();
bool blFind = false;
int length = strArrs.Length;
for (int i = 0; i < length; i++)
{
if (strArrs[i].Equals(strValue))
{
blFind = true;
}
if (blFind == true)
{
if (i == length - 1)
{
break;
}
strNewArrs.Add(strArrs[i+1]);
}
}
return strNewArrs;
}//只需要遍历一遍数组 #region 方法二
static int GetIndex(string[] strArrs, string strValue)
{
for (int i = 0; i < strArrs.Length; i++)
{
if (strArrs[i].Equals(strValue))
{
return ++i;
}
}
return -1;
} static string[] GetNewArrs(string[] strArrs, int index)
{
int length=strArrs.Length;
string[] strNewArrs=new string[length-index];
int i = -1;
for (; index < length; index++)
{
strNewArrs[++i] = strArrs[index];
}
return strNewArrs;
}
#endregion
}
}
解决方案 »
- 【求助】c#更新access数据库字段
- 求救以下Delphi代码,使用C#怎样实现。
- 请高手来帮帮菜鸟
- 问一个关于ShowDialog()打开的子窗体如何获取父窗体名字的问题
- picturebox
- c#操作Access时报错:不能更新;当前正在被机器'ZHANGTAO ' 上的用户 'admin ' 锁定。
- 多线程程序中如何使一段代码在同一时间只能有一个线程执行
- 小女子急求分类列表的做法
- 打包msde的时候怎么同时也附加 数据库 谢谢 麻烦进来解决下 谢谢了 在线等
- 求助怎么用C#实现RSA2048带RSA/ECB/oaepwithsha-512andmgf1padding填充的加密算法
- 请教C#中异常的内部机制
- c#如何调用api函数设置进程的优先级并查看优先级?
还是泛型好
是不是啊
static string[] GetNewArrs(string[] strArrs, int index)
static List<string> GetNewArrs(string[] strArrs, string strValue)
这两个哪个好?
第二个好一点,通过大量数据测试,速度快点,估计是IL优化了