Is there any class in the .NET Framework to represent a holding container for objects?
Posted
by Charles Prakash Dasari
on Stack Overflow
See other posts from Stack Overflow
or by Charles Prakash Dasari
Published on 2010-05-09T05:09:43Z
Indexed on
2010/05/09
9:48 UTC
Read the original article
Hit count: 230
I am looking for a class that defines a holding structure for an object. The value for this object could be set at a later time than when this container is created. It is useful to pass such a structure in lambdas or in callback functions etc.
Say:
class HoldObject<T> {
public T Value { get; set; }
public bool IsValueSet();
public void WaitUntilHasValue();
}
// and then we could use it like so ...
HoldObject<byte[]> downloadedBytes = new HoldObject<byte[]>();
DownloadBytes("http://www.stackoverflow.com", sender => downloadedBytes.Value = sender.GetBytes());
It is rather easy to define this structure, but I am trying to see if one is available in FCL. I also want this to be an efficient structure that has all needed features like thread safety, efficient waiting etc.
Any help is greatly appreciated.
© Stack Overflow or respective owner