The power of creating lazy objects

I am given a collection of elements Lazy. Then I want to forcibly “create” them all in one go.

void Test(IEnumerable<Lazy<MailMessage>> items){
}

Typically, with an element, the Lazycontained object will not be created until one of its members is available.

Having seen that there is no method ForceCreate()(or similar), I am forced to do the following:

var createdItems = items.Where(a => a.Value != null && a.Value.ToString() != null).Select(a => a.Value);

Used ToString()to create each item.

Is there a more accurate way to force the creation of all elements?

+4
source share
2 answers

, ( ), Value, .

items.All(x => x.Value != null);

All , , ( ) Value . ( != null , , All.)

+3

:

var created = items.Select(c => c.Value).ToList();
+3

All Articles