简体   繁体   English

在C#中从文本文件中读取大量整数(双精度)的最有效方法是什么?

[英]What is the most efficient way to read a lot of integers (doubles) from text file in C#?

If i have to read a huge matrix of integers from a file, what would be the most efficient way to do so in C#? 如果我必须从文件中读取巨大的整数矩阵,那么在C#中最有效的方法是什么?

Example : 范例:

n m // n - number of rows m - number of columns
a11  ... a1m
    ...
an1 ...  anm

Mostly it depends what you mean by efficient, in terms of speed once loaded loading into an multidimensional array and using this would be very quick. 通常,在将速度加载到多维数组中后,使用速度非常快,这取决于效率的含义。

In terms of only using the resources that you need, streaming the rows line by line would be best. 就仅使用所需的资源而言,最好逐​​行传输行。

In my opinion, after reading the whole text from file, you can use Regex class to match all numbers (using Matches(String) method) and retrieve an object of class Matches . 我认为,从文件中读取整个文本后,可以使用Regex类来匹配所有数字(使用Matches(String)方法)并检索Matches类的对象。 All the number under String form are stored in this object and you can obtain the numbers by parsing it from these string. 字符串形式的所有数字都存储在此对象中,您可以通过从这些字符串中进行解析来获取数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 C# 中的字节数组中读取字节的最有效方法是什么 - what is the most efficient way to read bytes from a byte array in C# 使用SqlDataReader(C#)从SQL Server读取许多字节的最有效方法是什么 - What is the most efficient way to read many bytes from SQL Server using SqlDataReader (C#) 随机“排序”(随机播放)C# 中的整数列表的最有效方法 - Most efficient way to randomly "sort" (Shuffle) a list of integers in C# 从C#更新许多行的有效方法 - Efficient Way to Update a lot of Rows from C# C# 读取文件内容、替换某些内容并最终将其加载为 XDocument 的最有效方法 - C# Most efficient way to read file content, replace some content and finally load it as XDocument 有没有最有效的方法来在C#中读取/写入最多10GB的二进制文件? - Is there a most efficient way to read/write upto 10GB binary file in C#? 什么是最有效(读取时间)字符串搜索方法? (C#) - What is the most efficient (read time) string search method? (C#) 使用C#更改文件中行尾的最有效方法是什么 - What is the most efficient way of changing line endings in a file using C# 在C#中将字节数组保存为磁盘上文件的最有效方法是什么? - What is the most efficient way to save a byte array as a file on disk in C#? 在Razor C#中呈现HTML表的最有效方法是什么 - What is the most efficient way to render a HTML Table in Razor C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM