

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Questions & Answers
- How to call a non-static method of an abstract class from a static method in java?
- How to call a method after a delay?
- How to call the constructor of a parent class in JavaScript?
- How to call a parent class function from derived class function in C++?
- How to call a method after a delay in Swift(iOS)?
- How to call a method after a delay in Android Kotlin?
- Call a method Asynchronously in C#
- How to declare, define and call a method in Java?
- Call a JavaScript class object with variable?
- How do we call a C# method recursively?
- How do we call a Java method recursively?
- What is a JavaScript call() Method?
- What is a recursive method call in C#?
- How to call an activity method from a fragment in Android App?
- How to explicitly call base class constructor from child class in C#?
Advertisements