TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Addition Method Within Main Class by Calling method In C#
Rajan Singh
Jun 11
2015
Code
8
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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#