Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:19:43+00:00 2026-06-13T05:19:43+00:00

I have a text file, where I have some points: 20,30 5,40 67,34 2,0

  • 0

I have a text file, where I have some points:

20,30
5,40
67,34
2,0
98,34

And how add this points to List? It’s my code what I made:

Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".txt";
dlg.Filter = "Text document (.txt)|*.txt";

Nullable<bool> result = dlg.ShowDialog();

if (result == true)
{
    string filename = dlg.FileName;
    _mn.nazwa_pliku.Text = filename;

    int num = 0; //get a number of points/line in file

    for (int i = 0; i < num; i++) //for everyone line/point
    {

        int x = 0; //get X-value from file
        int y = 0; //get Y-value from file

        Klaster klaster = new Klaster();
        klaster.Punkty.Add(new Point(x, y));
        Klastry.Add(klaster);
    }       
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:19:45+00:00Added an answer on June 13, 2026 at 5:19 am

    One way is to use File.OpenText and read line-by-line:

    // Open the stream and read it back. 
    string s;
    using (StreamReader sr = File.OpenText(filename)) 
    {
        while ((s = sr.ReadLine()) != null) 
        {
            // parse the string and add the values to the list
            string[] parts = s.Split(new [] {','});
            if(parts.Length != 2)
            {
                // throw an exception
            }
    
            int x, y;
    
            if (!int.TryParse(parts[0],out x) ||
                !int.TryParse(parts[1],out y))
            {
                // throw an exception
            }
    
            Klaster klaster = new Klaster();
            klaster.Punkty.Add(new Point(x, y));
            Klastry.Add(klaster);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have text file with some text information and i need to split this
I have some code reading a text file and scanning for words between brackets:
We have some C# code that reads data from a text file using a
In support of some legacy code, I have to read a text file and
I have text file with some stuff that i would like to put into
I have a text file that contains some strings separated by ,. Strings are
I have a text file where each line may end with some fixed TAG
I just started using/learning Python and have some questions. I have a text file
okay, so i have a text file with example content below line1with some random
I have to read a text file and based on some logic, make some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.