将textfile读入excel数组并计算平均值

时间:2015-09-02 20:30:12

标签: c# arrays streamreader

我试图将文本文件中的信息(只有6行5个数字)读入2D数组,并为平均值添加新列。

using System;
using System.IO;
public static class Program
{
    static void Main()
    {
        string file="marks2D.txt";
        string outfile="average.csv";
        StreamReader sr= new StreamReader(file);
        StreamWriter outstream= new StreamWriter(outfile);
        //double[] field=new double [0];
        string[,] temp=new string[5,6];
        int num=0;
        double ave=0;
        for(int i=0; i<temp.GetLength(0); i++)
        {
            double sum=0;
            string line=sr.ReadLine();
            //temp=line.Split(',');
            for(int j=0; j<temp.GetLength(1); j++)
            {
            double m=double.Parse(line);
            ave = m/5;
                temp[num]=line;
                outstream.WriteLine(ave);
                //Console.Write("{0,1}", temp[i,j]);
            }
            outstream.WriteLine(field[num]);
        }
        Console.WriteLine();
        sr.Close();
        outstream.Close();
    }
}

0 个答案:

没有答案