Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What is missing? C#

What is missing? C#

Scheduled Pinned Locked Moved C#
questioncsharpdata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adnanh75
    wrote on last edited by
    #1

    I am trying to read one text file, and create an Array.. Dos someone knews what am I doing wrong?? Can someone correct my code a little bit? private void panel13_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { ArrayList nodes = new ArrayList(); FileStream file = new FileStream("C:\\NeckingRa\\Temp\\cut.dat", FileMode.Open,FileAccess.Read); StreamReader sr = File.OpenText("C:\\NeckingRa\\Temp\\cut.dat"); String line; while ((line=sr.ReadLine())!=null) { string s = sr.ReadToEnd(); string[] values = line.Split(' '); } sr.Close(); file.Close(); }

    S 1 Reply Last reply
    0
    • A adnanh75

      I am trying to read one text file, and create an Array.. Dos someone knews what am I doing wrong?? Can someone correct my code a little bit? private void panel13_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { ArrayList nodes = new ArrayList(); FileStream file = new FileStream("C:\\NeckingRa\\Temp\\cut.dat", FileMode.Open,FileAccess.Read); StreamReader sr = File.OpenText("C:\\NeckingRa\\Temp\\cut.dat"); String line; while ((line=sr.ReadLine())!=null) { string s = sr.ReadToEnd(); string[] values = line.Split(' '); } sr.Close(); file.Close(); }

      S Offline
      S Offline
      Steve Maier
      wrote on last edited by
      #2

      I would make the code look like this:

      private void panel13_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
      {
      ArrayList nodes = new ArrayList();
      StreamReader sr = File.OpenText("C:\\NeckingRa\\Temp\\cut.dat");
      String line;
      while ((line=sr.ReadLine())!=null)
      {
      string[] values = line.Split(' ');
      nodes.AddRange(values);
      }
      sr.Close();
      }

      The file variable is not needed and inside of the while look you were reading to the end of the file. Also you had never added the data in values to the nodes variable. I also like using @"c:\NeckingRa\Temp\cut.dat" in C# instead of the normal \\ that we all had to use in C++. Steve Maier, MCSD MCAD

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups