|
-
February 8th, 2010, 07:06 AM
#1
Compilation errors
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.
-
February 8th, 2010, 07:35 AM
#2
Re: Compilation errors
 Originally Posted by nagarjuna02
Why the above code is giving errors?
why are not using the code tags?
 Originally Posted by nagarjuna02
I am new to C# programming.
you must really be new to this. you have defined a function inside another function and it's not even static like the main one. you need some book.
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
February 8th, 2010, 07:47 AM
#3
Re: Compilation errors
Posting exact text of the exception message, maybe including the stack, is very helpful.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
February 8th, 2010, 07:59 AM
#4
Re: Compilation errors
it doesn't matter what errors he has in this case. he's defined his find function inside the main function.
but yes, error messages are always helpful!
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
February 8th, 2010, 04:41 PM
#5
Re: Compilation errors
As already mentioned C# does not support nested functions. (at least not without the use of delegates and anonymous functions)
Define the "find" method outside the main method, and make it static so that the static main method will be able to find it.
Tags for this Thread
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
|