c# - Mutable wrapper of value types to pass into iterators -


I am writing an iterator, which needs to be passed around a temporary integer.

  Public IEnumerable & LT; T & gt; Foo (ref INT value value some) {// stuff yield returns ...; }  

This makes me net "Error 476 Iterators can not be referee or out parameter."

What I need to modify in Iterator is this integer value and it is the caller of the itater in other words, Foo () above what it calls < Wants to know the value of the code> valueThatMeansSomething and Foo () . In fact, I want an integer that is a reference type, not a value type.

The only thing I can think is writing a class that contains my integer and allows it to modify me.

Public Class ValueWrapper & lt; T & gt; Where T: structure {public value-wafer (t item) {this.Item = item; } Public T Items {Received; Set; }}

like this:

  Manapar & lt; Int & gt; W = new value on the & lt; Int & gt; (0); Fu (W) in Fur (T)} {// do stuff} if (W. item {0} {/ * do stuff * /}  

Is the class or mechanism already handled in this BCL? ValueWrapper & lt; T & gt; with any defect proposed above?

(My actual use is more complex than the example given above, so handle my variable within my foreach loop which calls foo () < / Code> is not an option. Duration.)

No, I am confident that such a thing in BCL There is nothing that can do this. Your best option is to make sure that you've proposed I think. The implementation of the ValueWrapper should not really be more complicated than what you have proposed.

Of course, this is not guaranteed to be thread-safe, but if you require that you simply change the automatic property to the standard value, change it to a backing variable and mark the field (value To insure is up-to-date at all times).


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -