एक विधि को कॉल करने के लिए, वस्तु के नाम के बाद विधि के नाम का उपयोग करें, उदाहरण के लिए, -
obj1. Display();
मान लें कि वर्ग का नाम ApplicationOne है, इसलिए विधि को कॉल करने के लिए -
ApplicationOne one = new ApplicationOne(); //calling the displayMax method ret = one.displayMax(a, b);को कॉल करना
C# में किसी विधि को कॉल करने का तरीका दिखाने वाला उदाहरण निम्नलिखित है -
उदाहरण
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();
}
}
} आउटपुट
Max value is : 700