Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to call a method of a class in C#
To call a method, use the name of the method after the object name, for example, −
obj1. Display();
Let’s say the class name is ApplicationOne, so to call the method −
ApplicationOne one = new ApplicationOne(); //calling the displayMax method ret = one.displayMax(a, b);
The following is the example showing how to call a method in C# −
Example
using System;
namespace Demp {
class ApplicationOne {
public int displayMax(int num1, int num2) {
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
static void Main(string[] args) {
/* local variable definition */
int a = 700;
int b = 400;
int ret;
ApplicationOne one = new ApplicationOne();
ret = one.displayMax(a, b);
Console.WriteLine("Max value is : {0}", ret );
Console.ReadLine();
}
}
}
Output
Max value is : 700
Advertisements