亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 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 關注
  • 154 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號