Geekpedia Forums Logo

System.IO

by Alejandro Gil on Friday, June 29th - 6:11 AM



I'm trying what the program read a determinate line of a text file but don't run. Someone can help me?.
Thx.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Prueba___IO
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StreamReader sr = new StreamReader("C:\\texto.txt");
            string texto;
            int linea = textBox1.Text;
            for (int i = 1; i >= linea; i++)
            {
                texto = sr.ReadLine();
            }
            label1.Text = texto;
        }
    }
}

Are you getting an exception?

In this line:
label1.Text=line;
Compiler say:
use local var not asigned 'line'

Sorry for my bad english.