Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#如何首先使用foreach循环从数组[1]而不是数组[0]中读取?_C#_Arrays_Foreach - Fatal编程技术网

C#如何首先使用foreach循环从数组[1]而不是数组[0]中读取?

C#如何首先使用foreach循环从数组[1]而不是数组[0]中读取?,c#,arrays,foreach,C#,Arrays,Foreach,我有一个关于从文本日志文件转换的数组的读取顺序的问题 由于在位于第一行[0]中的进程中存在不需要读取的文件头,是否有任何方法可以跳过读取行[0]并首先开始读取行[1] 该程序利用foreach循环读取数组。还有一种标记化方法,因此标记化需要foreach循环来重新组织数组的字符串格式 请提供代码方面的建议,以提供帮助!谢谢 程序代码: class Program { static void Main(string[] args) { System.Collecti

我有一个关于从文本日志文件转换的数组的读取顺序的问题

由于在位于第一行[0]中的进程中存在不需要读取的文件头,是否有任何方法可以跳过读取行[0]并首先开始读取行[1]

该程序利用foreach循环读取数组。还有一种标记化方法,因此标记化需要foreach循环来重新组织数组的字符串格式

请提供代码方面的建议,以提供帮助!谢谢

程序代码:

class Program
{
    static void Main(string[] args)
    {
        System.Collections.Generic.IEnumerable<String> lines = File.ReadLines("C:\\syscrawl\\ntfs3.txt");

        foreach (String r in lines) //Start reading from lines[1] first instead?
        {
            String[] token = r.Split(',');
        }
    }
}
使用扩展方法。例如

foreach (String r in lines.Skip(1)) //Start reading from lines[1] first instead
{
   String[] token = r.Split(',');
}
如果要检查行而不是依赖计数,可以使用。例如

使用:

foreach (String r in lines.Skip(1)) //Start reading from lines[1] first instead
{
   String[] token = r.Split(',');
}
foreach (String r in lines.SkipWhile(l => l.StartsWith(HeaderInfo)) 
{
   String[] token = r.Split(',');
}
foreach (String r in lines.Skip(1))