我这段代码有问题啊,到底在哪出问题了,代码中30是我瞎写的,要读完整个文件中的数据存入数组,是不是有length之类的函数可以计算长度?麻烦高手解决,很急啊,谢谢解答
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
StreamReader objReader = new StreamReader("d:\\C#.txt");
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
string[] array = arrText.Split(',');
objReader.Close();
for (int i = 0; i < 30; i++)
{
Console.WriteLine(array[i]);
}
}
}
}
鉴于帮助我的人的建议,代码修改如下,还是不对,望有人能运行一下代码,帮助我修改一下,谢谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
StreamReader objReader = new StreamReader("d:\\C#.txt");
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
arrText.Add(sLine);
}
string[] result = System.IO.File.ReadAllText("d:\\C#.txt").Split(',');
objReader.Close();
for (int i = 0; i < result.Length; i++)
{
Console.WriteLine(result[i]);
}
}
}
}