请高手看一段程序
using System;using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,] b = Matrix.ReadFromFile("C:\\1.txt");
for (int i = 0; i < b.GetLength(0); i++)
{
for (int j = 0; j < b.GetLength(1); j++)
{
Console.Write(b[i, j] + "\t");
}
Console.WriteLine();
}
}
}
public class Matrix
{
public static int[,] ReadFromFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
List<string> ls = new List<string>();
string str = sr.ReadLine();
while (str != null)
{
ls.Add(str);
str = sr.ReadLine();
}
sr.Close();
fs.Close();
if (ls.Count != 0)
{
int row = ls.Count;
int col = ls[0].Split(' ').Count();
int[,] array = new int[row, col];
for (int i = 0; i < row; i++)
{
string[] ss = ls[i].Split(' ');
for (int j = 0; j < ss.Count(); j++)
{
array[i, j] = int.Parse(ss[j]);
}
}
return array;
}
return null;
}
}
}
之后显示“System.Array”并不包含“Count”的定义这个问题,请问该如何修改呢?请教高手~~ --------------------编程问答-------------------- 数组只有Length --------------------编程问答-------------------- 使用.Net Framework 3.5以上 -> Linq
或直接用Length --------------------编程问答-------------------- 谢谢各位,我用vs2008,就没有此类问题,但是有了新的问题,就是运行时,为空的,难道是我的main()函数写错了? --------------------编程问答-------------------- 一步一步debug吧 --------------------编程问答-------------------- 代码没错。但楼主是否明白你这段代码的含义?
C:\1.txt 文件的内容:
1 2 3
4 5 6
7 8 9
补充:.NET技术 , C#