首页 > 解决方案 > 读取文件时出现 System.StackOverflowException c#

问题描述

我正在尝试将文件读入我的 wpf 程序,但 System.StackOverflowException 正在发生!任何帮助都会很棒,谢谢!!

我的代码:

 private void BestSellerListtxt_TextChanged(object sender, TextChangedEventArgs e)
    {
        string[] TopFictionArray = File.ReadAllLines("TopFiction.txt");
        string[] TopNonFictionArray = File.ReadAllLines("TopNonFiction.txt");

        for (int i = 0; i < TopFictionArray.Length; i++)
        {
            BestSellerListtxt.Text = TopFictionArray[i];
        }

        BestSellerListtxt.Text = "";

        for (int i = 0; i < TopNonFictionArray.Length; i++)
        {
            BestSellerListtxt.Text = TopNonFictionArray[i];
        }
    }

标签: c#file

解决方案


试试这个,在 string.Join(Delimeter, array) 的帮助下,您可以在不使用循环的情况下连接数组元素,并且可以轻松打印

BestSellerListtxt.Text = string.Join("," , TopFictionArray);

BestSellerListtxt_TextChanged = strin.join("," , TopNonFictionArray);

推荐阅读