C# work with functions
I'am new with C#. How works in C# functions?
My try:
private void Form1_Load(object 开发者_JS百科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
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;
}
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
Your function (typically referred to as a 'method' in C#) is defined as returning void. Change it to:
public int number_p(int number)
精彩评论