Cached property vs Lazy

后端 未结 7 1320

In .NET 4 the following snippet with a cached property can also be written using the System.Lazy class. I measured the performance of both approaches and it\'s pret

7条回答
  •  不思量自难忘°
    2020-12-04 13:53

    The Lazy is simpler—it clearly expresses the intent of the code.
    It's also thread safe.

    Note that if you're actually using this on multiple threads, you need to make it [ThreadStatic]; GDI+ objects cannot be shared across threads.

提交回复
热议问题