using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Hello World!");
int a = 10;
int b = 20;
Ca(a, b);
}
public static void Ca(int x,int y)
{
int m = x + y;
Console.WriteLine(m);
}
}
}
Among them, a and b are actual parameters, and x and y are formal parameters.
The parameters in the definition method are formal parameters, and the parameters in the calling method are actual parameters
like
int Add(int a,int b){//.....} There are two formal parameters ab in the Add method, and two comma-separated int actual parameters must be provided when calling, such as Add(30,20); You can also change the two actual parameters into int variable names, such as int x=30;int y=20;Add(x,y);
Method call:
When calling methods of other objects, the object name prefix should be added in front of the method name, such as
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp1
{
class Class1
{
public static void Tosting(int x,int y)
{
int m = x + y;
Console.WriteLine("x+y=" + m);
}
}
}
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
//Console.WriteLine("Hello World!");
int a = 10;
int b = 20;
Ca(a, b);
}
public static void Ca(int x,int y)
{
Class1.Tosting(x, y);//调用其它对象的方法
}
}
}