
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- How to call a parent method from a child class in JavaScript?
- How to call a non-static method of an abstract class from a static method in java?
- How to call the constructor of a parent class in JavaScript?
- How to call a method after a delay?
- 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?
- How to declare, define and call a method in Java?
- Call a method Asynchronously in C#
- How do we call a Java method recursively?
- How do we call a C# method recursively?
- How to call an activity method from a fragment in Android App?
- How to explicitly call base class constructor from child class in C#?
- Call a JavaScript class object with variable?
- How to call parent constructor in child class in PHP?

Advertisements