private void button1_Click(object sender, EventArgs e)
        {
            double[,] array = new double[10000, 3];
            int[] time = new int[10000];
            double[] p = new double[10000];
            double[] e0 = new double[10000];
            StreamReader pcpReader = new StreamReader("f:\\pcp.txt");如何赋值给数组array呢?
            for (int i = 2; i < 10000; i++)
            {
                time[i] = Convert.ToInt16(array[i, 0]);
                p[i] = array[i, 1];
                e0[i] = array[i, 2]; 
                richTextBox1.Text = Convert .ToString(p[i]);
               
            }
                    }
附txt文本1 22 4
2 10 0.1
4 24.1 0
6 20.4 0.1
8 18.3 0.5
10 10.1 0.7

解决方案 »

  1.   

    嗯  是这个意思  只要能把从txt导入的数组赋值给array就行了
    请问 具体怎么操作呢  能帮忙写下吗  多谢了
      

  2.   

    io readLine.
    之后split 分别放不您的数组即可。
      

  3.   

    你的意思是 数组 转 Array?
    数组有一个方法 CopyTo 你试一试!
      

  4.   


    关键是把txt问本利得数值赋值给程序里的array数组
      

  5.   


    //注意处理异常
    Double[,] parseText(String file)
            {
                Double[,] nums = new Double[1000, 3];
                StreamReader sr = new StreamReader(file);
                int i = 0;
                while (sr.Peek() > 0)
                {
                    String[] arr = sr.ReadLine().Split(' ');
                    nums[i, 0] = double.Parse(arr[0]);
                    nums[i, 1] = double.Parse(arr[1]);
                    nums[i, 2] = double.Parse(arr[2]);
                }
                sr.Close();
                sr.Dispose();
                return nums;
            }
      

  6.   

    参看我的http://topic.csdn.net/u/20100322/16/bc9f4a41-2286-4a2e-bfa5-2e5d84ada685.html
    换个数据就行了 前提是数据不要太大 不然用ReadToEnd就慢了 可以试着自己改一改哈using System;
    using System.Collections.Generic;
    //using System.Linq;
    using System.Text;
    using System.Net.Mail;
    using System.Threading;
    using System.IO;
    namespace mail
    {
        class Program
        {
            static void Main(string[] args)
            {            string path = @"D:/1.txt";
                string[,] str = new string[3,3];
                string temp = "";
                try
                {
                    FileStream fs = new FileStream(path, FileMode.Open);
                    using (StreamReader sr = new StreamReader(fs))
                    {                    string line = sr.ReadToEnd().Replace("\r", "").Replace("\n","");
                        string[] str2 = line.Split(' ');
                        for (int m = 0; m < 3; m++)
                            for (int n = 0; n < 3; n++)
                                str[m, n] = str2[3 * m + n];
                        foreach (string k in str)
                        {
                            temp += k + " ";
                        }    
                        Console.Write("读出的数组为:\n{0}", temp);
                        Console.ReadKey();                }
                }
                catch (Exception e)
                {
                    Console.Write("出现错误!{0}", e.Message);
                    Console.ReadKey();
                }
            }
        }
    }