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.