Pergunta

Orginnally I had a BlockingCollection

 BlockingCollection<ChannelResource> ChannelQueue = new BlockingCollection<ChannelResource>();

I added the items to it.

  ChannelResource ChanResource = TelephonyServer.GetChannel();
  MyApplication.ChannelQueue.TryAdd(ChanResource);

Now I find that each ChannelResource has a corresponding string, so I want to add ChannelResource object with the string together to the BlockingCollection.

How? Merge the object ChannelResource and the string to form an anonymous type?

EDIT:

I mean do I have to redifine the BlockingCollection as

BlockingCollection<T> ChannelQueue = new BlockingCollection<T>();

And T contains ChannelResource and string together?

Foi útil?

Solução

I suppose that you can use the Tuple class (http://msdn.microsoft.com/en-us/library/system.tuple.aspx), like this:

var ChannelQueue = new BlockingCollection<Tuple<ChannelResource, String>>();
ChannelResource ChanResource = TelephonyServer.GetChannel();
MyApplication.ChannelQueue.TryAdd(Tuple.Create(ChanResource, "someString"));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top