Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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#搜索vs读取_C#_Performance_File_Seek - Fatal编程技术网

c#搜索vs读取

c#搜索vs读取,c#,performance,file,seek,C#,Performance,File,Seek,为什么缓慢地读取文件进行查找更好 //if (!read_fields[x] || !ok) //{ // if (l > 0) Seek(l, SeekOrigin.Current); // read[x] = null; // continue; //}

为什么缓慢地读取文件进行查找更好

//if (!read_fields[x] || !ok)
                    //{
                    //    if (l > 0) Seek(l, SeekOrigin.Current);
                    //    read[x] = null;
                    //    continue;
                    //}

                    byte[] bx = new byte[l];
                    if (l > 0) Read(bx, 0, l);

                    if (!read_fields[x] || !ok)
                    {
                        read[x] = null;
                        continue;
                    }
我的速度测试显示搜索速度非常慢

-将此流的当前位置设置为给定值。 -从流中读取字节块,并将数据写入给定的缓冲区

因此,使用seek重新定位读取位置-这是一个耗时的过程。如果是简单读取,则按顺序读取文件。

请参阅: