using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Collections;
using System.IO;
namespace kongzhitai
{
 class Program
    {
        public static void Main()   //主程序部分,用来计算最终温度temperature;
        {
            double rou ;                                      //定义密度;
            double bire = 630;                                //定义比热;
            double lamda1 = 34;                              //定义x方向导热系数;
            double lamda2 = 38;                             //定义y方向导热系数;
            double temperature;
            rou = GetRou();                                //rou的值从方法中返回;
            temperature= lamda1*rou + lamda2 * bire;
            Console.WriteLine("{0}", temperature);
        }
        public double GetRou();                                     //此方法用来计算rou,并将rou的值返回,以便主程序调用;       {
               getValue xishu = new getValue();                   // xishu是从另一个类getValue中得到的;
               double a=0;
               double b=0;
              a = xishu.math();                                  //此方法用来计算rou,并将rou的值返回,以便主程序调用;
              b = xishu.math();
             result = a + b* 125;
             return result;
         }
  }
class getValue                                                 //此类用来读取指定文本文档的字符串,并将字符串分割,转化为double型;
       {                                                           //因为字符串被分割为多个数据,存到数组里,所以此类要返回多个值;
           public double[] math()  
         {
            double[] dblValues;
            string line = "";
            StreamReader sr = new StreamReader(@"E:\1.txt", System.Text.Encoding.GetEncoding("gb2312"));
            while ((sr.EndOfStream != true))
            {
                line = sr.ReadLine();
                string[] arr = line.Split(' ');
                dblValues = new double[arr.Length];
                for (int i = 0; i < arr.Length; i++)
                {
                    if (double.TryParse(arr[i], out dblValues[i]))
                    {
                        Console.WriteLine("{0}", dblValues[i]);
                    }
                }
            }
            return dblValues;
         }
       }
}
辛苦大家!这个程序主要是先读取文本文档的值,分割转化为double型,因为是多个值,所以存到数组里了。我想问的是其他程序调用时怎样区分我存到数组里的值,恳请大家帮我把程序调通,我很笨,做不来。谢谢大家!

解决方案 »

  1.   

    封装到一个 结构 或者 数组 在不就是 ref 传进来参数 赋值
      

  2.   

      public void Single_Multi_system(DataTable st, DataTable st_bili, out DataSet ds_dt_play, out DataTable dt_call_back_play, out DataTable dt_no_Profit_play)
        {
    }
    out 的部分就是返回值,想返回几个就几个
      

  3.   

    可以通过return
    回来一个数组么?
    在下如果是需要多return结果都是这样处理
    然后再通过其他方法处理结果
      

  4.   


    class Results
            {
                public int errorCode;            public string errorMsg;
            }        private Results GetLotsOfResults()
            {
                Results res = new Results();            res.errorCode = 1;
                res.errorMsg = "error!";            return res;
            }        private void GetLotsOfResults(string inParam, ref int errorCode, ref string errorMsg)
            {
                errorCode = 1;
                errorMsg = "Error!!";
            }
            void foo()
            {
    Results ret = GetLotsOfResults();
    //使用ret//一种方法
                string errorMsg = string.Empty;
                int errorCode = 0;            GetLotsOfResults("This is what you need to passed in", ref errorCode, ref errorMsg);        }