Lazy用法

   public class StudentInfo 
   {
       public static StudentInfo studentLazy = new Lazy<StudentInfo>(() => new StudentInfo()).Value;
       public int StudentID{ get; set; }

   }


   public partial class MainWindow : Window
   {
       public MainWindow()
       {
           InitializeComponent();
       }

       private void Button_Click(object sender, RoutedEventArgs e)
       {
           StudentInfo.studentLazy.StudentID = 999;
       }

       private void Button1_Click(object sender, RoutedEventArgs e)
       {
           var test = StudentInfo.studentLazy.StudentID;
       }
   }
posted @ 2023-02-28 09:59  *飞*  阅读(17)  评论(0编辑  收藏  举报