When to lazy load?

后端 未结 8 1836
庸人自扰
庸人自扰 2020-12-31 17:14

I lazy load all my members. I have been doing this for a while and simply taken lazy load to be a good thing at face value.

Let\'s say we have

publi         


        
8条回答
  •  说谎
    说谎 (楼主)
    2020-12-31 17:47

    List number = new List { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var result = number.Where(x => x % 2 == 0);
            number.Add(20);
            //foreach (int item in result)
            //{
            //    Console.WriteLine("loop1:" + item);
            //}
    
            foreach (int item in result)
            {
                if (item == 4)
                    break;
                Console.WriteLine("loop2:" + item);
            }
            number.Add(40);
            foreach (int item in result)
            {
    
                Console.WriteLine("loop3:"+item);
            }
            Console.ReadLine();
    

    uncomment first loop and see the difference. very using example to under stand deffred execution and lazy loading.

提交回复
热议问题