Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6.  
  7. namespace PEA1_WindowApp
  8. {
  9.     class ReadData
  10.     {
  11.         public int vertex { get; set; }
  12.         public List<string> list = new List<string>();
  13.  
  14.         public ReadData()
  15.         {
  16.             vertex = 0;
  17.         }
  18.  
  19.         public void ReadFromFile()
  20.         {
  21.             list.Clear();
  22.             string path;
  23.             OpenFileDialog file = new OpenFileDialog();
  24.             if (file.ShowDialog() == DialogResult.OK)
  25.             {
  26.                 path = file.FileName;
  27.                 FileStream f = File.OpenRead(path);
  28.                 StreamReader reader = new StreamReader(f);
  29.                 string str = reader.ReadLine();
  30.  
  31.                 str = File.ReadLines(path).First();
  32.                 vertex = Int32.Parse(str);
  33.  
  34.                 var fileText = File.ReadAllLines(path).Skip(1);
  35.  
  36.                 foreach (object item in fileText)
  37.                 {
  38.                     list.Add(item.ToString());
  39.                 }
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement