Last active
March 30, 2024 03:12
-
-
Save normanlmfung/3c960e19c829fa38617076ae7147b169 to your computer and use it in GitHub Desktop.
csharp_lazy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lazyString = new Lazy<string>( | |
() => | |
{ | |
// Here you can do some complex processing | |
// and then return a value. | |
Console.WriteLine("Inside lazy loader"); | |
return "Lazy loading!"; | |
}); | |
Console.WriteLine($"Is value created: {lazyString.IsValueCreated}"); // false | |
var lazyValue = lazyString.Value; | |
Console.WriteLine($"lazyValue: {lazyValue}"); | |
Console.WriteLine($"lazyString.Value: {lazyString.Value}"); | |
Console.WriteLine($"Is value created: {lazyString.IsValueCreated}"); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment