C# OpenFileDialog

jiyul·2023년 12월 11일
0

C#

목록 보기
16/21

OpenFileDialog로 텍스트 파일 읽기

OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
{
    FilePathLabel.Content = openFileDialog.FileName;
    StreamReader sr = new StreamReader(openFileDialog.FileName);
    
    List<Person> list = new List<Person>();
    while(!sr.EndOfStream)
    {
        try
        {
            string line = sr.ReadLine();
            string[] data = line.Split(',');
            list.Add(new Person { name = data[0], age = data[1], info = data[2] });
        }
        catch (Exception ex) 
        {
            MessageBox.Show(ex.Message);
        }
	}
    StudentList.ItemsSource = list;
}
profile
Let's take the lead

0개의 댓글

관련 채용 정보