为了账号安全,请及时绑定邮箱和手机立即绑定

将 Reader 流式传输到列表、列表到数组并拆分行值,创建拆分值的对象并将其打印为

将 Reader 流式传输到列表、列表到数组并拆分行值,创建拆分值的对象并将其打印为

PHP
墨色风雨 2024-01-20 15:53:10
将 Reader 流式传输到列表、列表到数组并拆分行值,创建拆分值的对象并将其打印为 RichTextBox 中的随机对象
查看完整描述

1 回答

?
幕布斯7119047

TA贡献1794条经验 获得超8个赞

尝试以下更简单的方法:


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;


namespace Övning_3___Tipsmaskinen2

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void Button1_Click(object sender, EventArgs e)

        {

            FileLoader();

        }

        public class Bok

        {

            public string Titel;//Tittle

            public string Författare;//Author

            public string Boktyp;//TBookTYp

            public string ILager;// Bool or InSToridge 


            public Bok(string titel, string författare, string boktyp, string ilager) // method must have a return typ , funkar enbart om jag skriver in void

            {

                this.Titel = titel;

                this.Författare = författare;

                this.Boktyp = boktyp;

                this.ILager = ilager;

            }


            public override string ToString()

            {

                return "\t Titel : " + Titel + "\t Skribent : " + Författare + "  \t Boktyp: " + Boktyp + " \t Finns i lager : " + ILager;

            }

        }

        public List<Bok> FileLoader()

        {

            List<Bok> bokList = new List<Bok>();

            if (File.Exists("texter.txt"))

            {

                StreamReader reader = new StreamReader("texter.txt", Encoding.Default, true);



                string item = "";

                while ((item = reader.ReadLine()) != null)

                {

                    string[] vektor = item.Split(new string[] { "###" }, StringSplitOptions.None);


                    Bok k = new Bok(vektor[0], vektor[1], vektor[2], vektor[3]);

                    bokList.Add(k);

                }

                return bokList;

            }

            return null;


        }

    }

}


查看完整回答
反对 回复 2024-01-20
  • 1 回答
  • 0 关注
  • 23 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信