The basic: Functions (problems)

Reply Forum
Forum postlol2 @ 2009-02-03 04:42:21
ReplyReply to
Hi :)

Im really happy for your guide to C# so far.
But im having problems with the functions.

I Can't get it to work, I have tried alot of combinations
over several hours now, and it just keep getting errors.

1: }Expected.
2: Type of namespace defination, or end of file expected.

My code right now looks like this (the last example)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void lol(string[] args)
{(this is where the first error occurs)
public int AddNumbers(int number1, int number2)
{
int result = number1 + number2;
if(result > 10)
{
return result;
}
return 0;
}

}
}
}(this is where the second error occurs)

I really hope you guys can help me out
because I'm seriously stuck :(

Regards Bjarke



Forum postWebmaster @ 2009-02-09 10:58:24
ReplyReply to
Hi Bjarke,

The problem is that you have placed the AddNumbers method inside the contructor method of your class. It should be outside of it, like this:

static void lol(string[] args)
{

}
public int AddNumbers(int number1, int number2)
{

}











© net-tutorials.com 2006 - 2012

MailContact net-tutorials.com