Thread: Compilation Errors

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    1

    Compilation 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));
            }
            
        }
    Why the above code is giving errors?

    I am new to C# programming

  2. #2
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    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.

  3. #3
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking and compilation errors
    By _lazycat_ in forum Windows Programming
    Replies: 2
    Last Post: 02-13-2009, 07:16 AM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. multiple errors generated by socket headers
    By nocturna_gr in forum Windows Programming
    Replies: 5
    Last Post: 12-16-2007, 06:33 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM

Tags for this Thread