int sum=0;
ArrayList al = new ArrayList();
private void button1_Click(object sender, EventArgs e)
...{
string str="";
FileStream s = new FileStream(@"I:\q.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(s,System.Text.Encoding.Default );
do
...{
str=sr.ReadLine();
sum++;
al.Add(str+"\r\n");
}while(str!=null || str=="");
string[] line = new string[al.Count+1];
al.CopyTo(line, 0);
for (int i = 0; i < line.Length ; i++)
str += line[i];
textBox1.Text = str;
Text = sum.ToString();
}
C#創建動態數組
using System;
using System.Collections;
public class SC
...{
static void Main()
...{
ArrayList al=new ArrayList();
al.Add("Hello");
al.Add(" ");
al.Add("World");
al.Add("!");
string[] str=new string[al.Count];
al.CopyTo(str,0);//從第0個位置開始復制
for(int i=0;i<str.Length;i++)
...{
Console.WriteLine(i.ToString()+str[i]);
}
}
}