- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Method Parameters in C#
The parameters are used to pass and receive data from a method. Let us first see the syntax −
- Access Specifier − This determines the visibility of a variable or a method from another class.
- Return type − A method may return a value. The return type is the data type of the value the method returns. If the method is not returning any values, then the return type is void.
- Method name − Method name is a unique identifier and it is case sensitive. It cannot be same as any other identifier declared in the class.
- Parameter list − Enclosed between parentheses, the parameters are used to pass and receive data from a method. The parameter list refers to the type, order, and number of the parameters of a method. Parameters are optional; that is, a method may contain no parameters.
- Method body − This contains the set of instructions needed to complete the required activity.
Example
Let us see an example −
using System; public class NumberManipulator { public int FindMax(int num1, int num2) { int result; if (num1 > num2) result = num1; else result = num2; return result; } public static void Main(string[] args) { int a = 500; int b = 750; int ret; NumberManipulator n = new NumberManipulator(); ret = n.FindMax(a, b); Console.WriteLine("Max value = "+ret ); } }
Output
This will produce the following output −
Max value = 750
Advertisements