如何在 C# 中调用类的方法
要调用方法,请在对象名称后使用该方法的名称,例如,−
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP