[英]reading a specific line from a textfile c# with a unique code that will display the line number
I want to read a specific line from a textfile in C# language with a unique code that will display the line number, And I am struggling to get this on any website, They show a lot but not exactly what I am looking for, This is my code:- 我想使用唯一的代码从C#语言的文本文件中读取特定行,该代码将显示行号,而我正努力在任何网站上获取该行,它们显示了很多但不完全是我想要的内容,这是我的代码:
namespace MyQuestion2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDisplay_Click(object sender, EventArgs e)
{
//opens the file dialog
OpenFileDialog ofd = new OpenFileDialog();
//checks to see if the user does open a file dialog
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//reads the file that the user opens
StreamReader sr = new StreamReader(File.OpenRead(ofd.FileName));
txtOutput.Text = sr.ReadToEnd();
sr.Dispose();
}
}
private void TxtProductCode_TextChanged(object sender, CancelEventArgs e)
{
TextBox tb = sender as TextBox;
if (tb != null)
{
int i;
if (int.TryParse(tb.Text, out i))
{
if (i >= 0 && i <= 5)
return;
}
}
MessageBox.Show("The number you have put is less than 0 or higher that 5! Please try again");
e.Cancel = true;
}
}
}
Thanks in advance. 提前致谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.