Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Recursive Method calls in C#
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00961245
Message ID:
00961246
Views:
4
Gerard,
Yes it is possible to use recursion in C#. It is a very powerful tool. There is a limit on the number of recursive calls (I can't remember the number of the top of my head), but it is a fairly high number.

The example you listed would eventually crash because counter is never updated so counter<10 will always be true, but if you update your counter variable in your recursive method your example should work.

Any variable defined in a recursive method is local to that instance of the recursive call, and will allocate new memory each time.

The consept of recursion is simple but can be a tough consept to get a grasp on, I would suggest reading up on the topic and then writing several test programs with a lot of messageboxes to monitor what is going on.

Hope this helped.

Einar


>Is it possible to call a Method from within a method and are Variable retained from Calling Method:
>e.g.
>
>class myclass()
>{
> public counter
> counter = 0
>
> MyMethod(int y);
> {
> int x
> x=y+1
> if (counter < 10)
> {
> MyMethod(x);
> }
> }
>}
>
>Are each of the x local to each recursive call , ot is the variable x the just taking up the same area in memory for each call
>
>
>
>Regards,
>Gerard
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform