1、取得最大值类:
class GetMax
{
public static double GetMaxNum(double NumOne,double NumTwo,double NumThree)
{
return Math.Max(Math.Max(NumOne, NumTwo), NumThree);
}
}
2、基类MyClass
abstract class MyClass
{
private string myString = "我是基类中的默认值 ";
public string ContainedString
{
set { myString = value; }
}
public virtual string GetString()
{
return myString;
}
}
3、子类MyDerivedClass
class MyDerivedClass:MyClass
{
public override string GetString()
{
return base.GetString() + "output from derived class";
}
}
主函数代码:
static void Main(string[] args)
{
//最大值
double Num1, Num2, Num3;
Console.WriteLine("请输入三个数字");
Num1 =Convert .ToDouble( Console.ReadLine());
Num2 = Convert.ToDouble(Console.ReadLine());
Num3 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("三个数中的最大值是:{0}",GetMax.GetMaxNum(Num1,Num2,Num3));
//输入基类和子类中的内容
MyClass myclass = new MyDerivedClass();
Console.Write(myclass.GetString());
Console.Read();
}
温馨提示:答案为网友推荐,仅供参考