• C#IO流-StreamReader( 冒泡求值拓展)


    /// <summary>
    /// 读取文本数据
    /// </summary>
    static void FileRead() {

    string path = @"F:\C#IO.txt";//文件的路径
    StreamReader reader = new StreamReader(path, Encoding.Default);//
    ArrayList arr = new ArrayList();
    while (true)
    {

    string readnext = reader.ReadLine();//因为reader.ReadLine();读对文件的读取是一行一行的读取文字
    //所以在这里添加了对所读的行数是否存在数据进行判断
    if (readnext == null) //为空的时候跳出循环-使用break
    {
    break;
    }
    else
    {
    arr.Add(readnext); //不为空的时候将所读的数据导入集合arr中,使用-add()方法每次添加元素到末尾
    //文本一共有多少行的数据就添加几次,相当于数组中的每一个元素
    }

    }
    string[] getvalue = (string[])arr.ToArray(typeof(string));
    string Getvalue = null;
    for (int i = 0; i < arr.Count; i++)//这里直接使用集合的行数作为循环终止条件
    {
    Getvalue += getvalue[i];//此处循环累加字符串
    }

    string[] Realnum = Getvalue.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    int[] arry = new int[Realnum.Length];
    for (int i = 0; i < Realnum.Length; i++)
    {
    //arry[i] = int.Parse(arr[i].ToString());
    arry[i] = int.Parse(Realnum[i]);

    }
    Console.WriteLine("{0},{1}", Realnum.Length, arry.Length);
    ReturnBigSmall(arry);
    Console.ReadKey();

    }
    /// <summary>
    /// 传入需要从大到小的int数组
    /// </summary>
    /// <param name="arr"></param>
    static void ReturnBigSmall(int[] arr)
    {
    int temp = 0;
    for (int j = 0; j < arr.Length - 1; j++)
    {
    for (int i = 0; i < arr.Length - 1 - j; i++)
    {
    if (arr[i] < arr[i + 1])
    {
    temp = arr[i + 1];
    arr[i + 1] = arr[i];
    arr[i] = temp;
    }

    }
    }
    for (int i = 0; i < arr.Length; i++)
    {
    Console.WriteLine("{0} ", arr[i]);
    }
    }

  • 相关阅读:
    Match function in R
    Excel lastindex of a substring
    Print a file's last modified date in Bash
    IQR(Inter-Quartile Range)
    nohup 让进程在后台可靠运行的几种方法
    extension(类扩展)和 category(类别)
    Dart学习-操作符
    为什么我觉得Python烂的要死?
    自定义 Cordova插件(基础篇)
    Cordova入门系列(四)自定义Cordova插件--showToast
  • 原文地址:https://www.cnblogs.com/Kai-YoungMaster/p/12386674.html
Copyright © 2020-2023  润新知