Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Addition Method Within Main Class by Calling method In C#
WhatsApp
Rajan Singh
Jun 11
2015
8.3
k
0
0
The method definition specifies the names and types of any parameters that are required. When calling code calls the method, it provides concrete values called arguments for each parameter. The arguments must be compatible with the parameter type but the argument name (if any) used in the calling code does not have to be the same as the parameter named defined in the method.
using
System;
class
MethodCalling
{
public
static
void
Main(
string
[] args)
{
int
value1 = 0, value2 = 0;
int
total = 0;
Console.Write(
"Enter first value: "
);
value1 = Convert.ToInt32(Console.ReadLine());
Console.Write(
"Enter second value: "
);
value2 = Convert.ToInt32(Console.ReadLine());
total = addition(value1, value2);
Console.WriteLine(
"Total of {0} and {1} is {2}"
, value1, value2, total);
}
static
int
addition(
int
x,
int
y)
{
return
x + y;
}
}
Output
Enter first value: 4
Enter second value: 5
Total of 4 and 5 is 9
Addition Method
Calling method In C#
C#
Up Next
Addition Method Within Main Class by Calling method In C#