Why the above code is giving errors?Code:using System; class program { static void Main(string[] args) { public int find( int n, int p) { if(n==0) return p; else return find(p%n,n); } Console.WriteLine( find(12,8)); } }
I am new to C# programming
Why the above code is giving errors?Code:using System; class program { static void Main(string[] args) { public int find( int n, int p) { if(n==0) return p; else return find(p%n,n); } Console.WriteLine( find(12,8)); } }
I am new to C# programming
1. You shouldn't have a method (find) within a method (Main).
2. Even with find as a seperate method within the Program class, it can't be reached from Main as it is not a static method.
Here is your example that will work. And make sure you understand the difference between a static method and non-static method. And a c# standard is to have methods with the first letter capitalized.
Code:using System; namespace MessinAround { class Program { static void Main(string[] args) { Console.WriteLine(Find(12, 8)); Console.Read(); } static int Find(int n, int p) { if (n == 0) return p; else return find(p % n, n); } } }
Last edited by stumon; 02-10-2010 at 09:00 PM.
The keyboard is the standard device used to cause computer errors!