[英]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.