0

I'am new with C#. How works in C# functions?

My try:

        private void Form1_Load(object sender, EventArgs e)
    {
        MessageBox.Show(Convert.ToString(number_p(5)));            
    }

    public void number_p(int number)
    {
        int one = 1;
        number = number + one;
        return number;
    }

Error: return, why? Thanks

1
  • Could you put what the error is in the question please? Commented May 20, 2010 at 5:24

3 Answers 3

5

At first glance, it looks like the problem may be that your function is declared to return void (i.e. nothing). Try changing it to return int.

public int number_p(int number)
{
    int one = 1;
    number = number + one;
    return number;
}
Sign up to request clarification or add additional context in comments.

Comments

4

You Method is of type "void" so there is no return value

If you want to return a number of type int you have to declare your method to be of type int instead of void

Maybe you should grab a book and read the very raw principles of c# first before posting here

1 Comment

Not only C#, but the basic principles of imperative programming.
1

Your function (typically referred to as a 'method' in C#) is defined as returning void. Change it to:

public int number_p(int number)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.