1、三元运算符:
class Program
{
static void Main(string[] args)
{
int max= NumMAX(,);
Console.WriteLine("最大数:{0}",max);
Console.ReadKey();
}
/// <summary>
/// 两个数中最大的值
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns></returns>
private static int NumMAX(int p1, int p2)
{
return p1 > p2 ? p1 : p2;
}
}
2、if条件判断:
class Program
{
static void Main(string[] args)
{
int max= NumMAX(,);
Console.WriteLine("最大数:{0}",max);
Console.ReadKey();
}
/// <summary>
/// 两个数中最大的值
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns></returns>
private static int NumMAX(int p1, int p2)
{
if (p1>p2)
{
return p1;
}
return p2;
}
}
3、Math函数:
class Program
{
static void Main(string[] args)
{
int max= NumMAX(,);
Console.WriteLine("最大数:{0}",max);
Console.ReadKey();
}
/// <summary>
/// 两个数中最大的值
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns></returns>
private static int NumMAX(int p1, int p2)
{
return Math.Max(p1, p2);
}
}