-
November 12th, 2009, 09:17 AM
#1
yield
Hello,
I was wonder if there's any chance to use the recursion in a mathod with yield instruction within a foeach, like this:
Code:
public IEnumerable<string> compute(string query) {
foreach (string s in myObjs) {
.......................................
compute(query++)
if (...) yield return query;
}
}
I don't know where's the problem but not recursion happen at all
-
November 12th, 2009, 01:02 PM
#2
Re: yield
Originally Posted by mickey0
Hello,
I was wonder if there's any chance to use the recursion in a mathod with yield instruction within a foeach, like this:
Code:
public IEnumerable<string> compute(string query) {
foreach (string s in myObjs) {
.......................................
compute(query++)
if (...) yield return query;
}
}
I don't know where's the problem but not recursion happen at all
Because yield has nothing to do with recursion. Recursion occurs when a method calls itself *recursively*. This is not a common thing to do in C# as it does not support tail recursion, so you may well blow your stack.
Also, your code makes absolutely no sense (incrementing a string???) and would not even compile. You should spend some time learning the basics before messing around with iterators and recursive functions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|