ienumerator

IEnumerable and IEnumerator in the same class, bad idea?

房东的猫 提交于 2021-01-27 04:44:11
问题 Is this a bad idea? Private Class GH_DataStructureEnumerator(Of Q As Types.IGH_Goo) Implements IEnumerable(Of Q) Implements IEnumerator(Of Q) .... .... 'Current, MoveNext, Reset etc.' .... .... Public Function GetEnumerator_Generic() As IEnumerator(Of Q) _ Implements IEnumerable(Of Q).GetEnumerator Return Me End Function End Class This class is only visible as an IEnumerable(Of T) readonly property, and it saves me an additional class that wraps IEnumerator(Of T). But somehow it just seems

IEnumerator yielding to the result of another IEnumerator

半腔热情 提交于 2021-01-07 05:07:18
问题 I have two classes set up in my project. On a button press in the first class I am calling the first IEnumerator on a button press: if(GUI.Button(new Rect(250, 0, 100, 20), "clear")) { StartCoroutine(Foo.test()); } The method being called looks like this (in the other class): public static IEnumerator test() { yield return StartCoroutine(DownloadAndCache()); // do stuff } However, I'm intending this method to only carry out its actions once it gets a return from a second IEnumerator that

How to Use IEnumerator Correctly when button calls multiple functions

非 Y 不嫁゛ 提交于 2020-06-29 04:33:41
问题 I am making a card game in which I am trying to make a (0.5f) delay before each card is instantiated. I have my code which instantiates and object public IEnumerator Name(int x,int y, int z) { } In the IEnum i have a yeild return new WaitForSeconds(0.5f) before all the code with the instantiation. I call my IEnumerator in 2 different classes 2 times in each by using StartCoroutine(Name(...par...)); And on my play game button i have 4 events which use the enum to spawn the cards but there is

Returning sprite from coroutine [duplicate]

≯℡__Kan透↙ 提交于 2020-01-25 06:45:47
问题 This question already has answers here : Unity - need to return value only after coroutine finishes (2 answers) Closed 2 years ago . I currently have 2 functions. My first one is an IEnumerator , let's call it LoadImage , it handles downloading the image from a URL. IEnumerator LoadImage() { WWW www = new WWW("https://s3-ap-northeast-1.amazonaws.com/myeyehouse/uimg/scimg/sc661120171130095837184/pano/thumb_Eyehouse.jpg"); while (!www.isDone) { Debug.Log("Download image on progress" + www

implementing IEnumerable<T> and IEnumerable.GetEnumerator() can not be public, why?

五迷三道 提交于 2020-01-11 09:59:13
问题 To implement an interface member, the corresponding member of the implementing class must be public. source: Interfaces (C# Programming Guide) I know it works if its private, but i would like to understand why it can not be public ? 回答1: When implemented explicitly interface methods are public by default and that's why you cannot use access modifiers. A quote from msdn.com : When a member is explicitly implemented, it cannot be accessed through a class instance, but only through an instance

IEnumerator: Is it normal to have an empty Dispose method?

我的未来我决定 提交于 2020-01-02 01:08:06
问题 I'm writing an IEnumerator<T> class to iterate over a COM collection I'm wrappering. I've noticed that IEnumerator<T> extends IDisposable, so I'm required to implement the Dispose method. However, I can't think of anything I would put there, as I only have a reference to the collection (which I wouldn't want being disposed at the end of a foreach ), and an int for the index. Is it normal to leave the Dispose method empty? 回答1: Yes, it is. IEnumerator<T> implements IDisposable in case you make

Refer to one of many coroutines in Unity3D?

…衆ロ難τιáo~ 提交于 2019-12-24 13:58:01
问题 Is there a way to have a variable point to one of a number of coroutines in C# in Unity3D? public class Example : MonoBehaviour { ? something ? crt; private IEnumerator CoroutineA() { } private IEnumerator CoroutineB() { } void Start() { crt = CoroutineA; StartCoroutine(crt); } } 回答1: The type that you are looking for is a delegate. Delegates are similar to function pointers, and are not specific to Unity3D. public class Example : MonoBehaviour { private delegate IEnumerator CoroutineDelegate

Serialization on classes that implement IEnumerator

≯℡__Kan透↙ 提交于 2019-12-24 00:59:59
问题 I have written a program which will serialize and de-serialize, it does this fine (I plan on implementing it on the subclasses once I get it properly working on one). However I have run into trouble when I decided I wanted to be able to iterate through the results using a Foreach . After this didn't work I to find out had to implement the IEnumerator and IEnumerable interfaces and add the required methods to my class. So I have, and this does allow me to loop through my collections. The

What interface to I need to implement to allow ForEach in VBA on a COM object written in delphi?

馋奶兔 提交于 2019-12-23 15:48:15
问题 Imagine I want to do something like this in VBA (pseudocode), and assuming my has an enumerable property IDList: Dim MyObject object set MyObject= CreateObject("MyObjectClass") for each Item as integer in MyObject.IDList Debug.Write(Cstr(Item) & ";") Next What would my property IDList have to look like in Delphi? Simply deriving it from IEnumerable<integer> or IEnumerable does not seem to do the job. Base code In order to avoid trouble with the default IENum and IEnum<T> interfaces I have

How yield return works in c#

泪湿孤枕 提交于 2019-12-23 12:28:39
问题 I have following piece of code. public static void main(string []args) { var intergers = GetCollection(); foreach(var val in intergers) { console.writeline(val); } } public IEnumerable<int> GetCollection() { yield return 10; var obj = new MyClass(); obj.performLargeAction(); yield return 1; var obj = new MyClass(); obj.perform(); yield return 2; console.writeline("I am finished now"); } Now, when I debug the code and see the foreach iteration, then I see that first time method executes till