2017-06-05 58 views
0

我想在文本框或列表框中顯示我的值。我有一個學生課,主要形式,另一種形式來添加學生。我成功地將學生添加到字典中,並且鍵是學生ID,還有其他值(名,姓等)。現在我想要將名字檢索到列表框或文本框。我怎樣才能做到這一點? 我添加了一個屏幕顯示,使其略顯清晰。 enter image description here在文本框或列表框中顯示值c#

+0

你在哪裏存放呢? – Krishna

+0

字典對象在主窗體和其他窗體中均創建。但是從其他形式使用函數將值傳遞給主窗體。我不確定這是否正確。 – Buddhi

+0

應用程序關閉後,你不需要這些數據? – Krishna

回答

0

試試這個

創建一個學生類

public class Student 
{ 
     public string StudentID { get; set; } 
     public string StudentName { get; set; } 
     //remaining properties 
} 

創建回購

public static class StudentRepository 
{ 
    private static List<Student> students = new List<Student>(); 
    public static void AddOrUpdateStudent(Student s) 
    { 
      var stu = students.Where(m=>m.StudentID = s.StudentID).FirstOrDefault(); 
      if(stu == null) 
      { 
       students.Add(s); 
      } 
      else 
      { 
       students.remove(stu); 
       students.Add(s); 
      } 

    } 
} 

形式使用該如下

StudentRepository.AddOrUpdateStudent(s); 
相關問題