Text Fileto Add in List<T>.

MiPakTeh 1,476 Reputation points

Hi All,
I have textfile contain 3 lines.

// line1 3518,4745
// line2 9019,0396

// line3 4753,9196

TODO, line1 3518,4745 put in Data2.
line2 9019,0396 put in Data3'
line3 4753,9196 put in Data4'

using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.IO;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.Windows.Forms;  
namespace Str3Number_  
    public partial class Form1 : Form  
        List<string> Data1 = new List<string>();  
        List<string> Data2 = new List<string>();  
        List<string> Data3 = new List<string>();  
        List<string> Data4 = new List<string>();  
        List<string> Data5 = new List<string>();  
        public Form1()  
        private void Form1_Load(object sender, EventArgs e)  
            foreach (var s in File.ReadLines(@"C:\Users\family\Documents\3digit_one.txt"))  

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,198 questions
{count} votes

Accepted answer
  1. Jack J Jun 24,281 Reputation points Microsoft Vendor

    @MiPakTeh , Welcome to Microsoft Q&A, based on your description, you want to load the text file into 3 different list.

    I suggest that you could create a list of list<string>, here is a code example you could refer to.



    Best Regards,


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful