1 Star 0 Fork 50

陌./C_sharp面向对象笔记

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Shape.cs 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
刘涛 提交于 2022-04-25 17:29 +08:00 . 笔记
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp1
{
class Shape
{
// 创建一个Shape类,此类包含一个名为color的数据成员(用于存放颜色值)和一个
//GetColor方法(用于获取颜色值),这个类还包含一个名为GetArea的虚方法。
//用这个类创建名为Circle和Square的两个子类,这两个类都包含两个数据成员,
//即radius和sideLen。这些派生类应提供GetArea方法的实现,以计算相应形状的
//面积。
public string color;
public string GetColor () {
return color;
}
public virtual double GetArea (){
return 0;
}
}
class Circle:Shape {
public double radius { get; set; }
public override double GetArea()
{
return radius * radius * 3.14;
}
public Circle(double radius) {
this.radius = radius;
}
}
class Square:Shape {
public double sideLen { get; set; }
public override double GetArea()
{
Console.WriteLine("赋值结果{0}",sideLen);
return sideLen * sideLen;
}
public Square(double sideLen) {
Console.WriteLine("闯入的参数{0}", sideLen);
this.sideLen = sideLen;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chen-li-xing/c-sharp-object-oriented-notes.git
git@gitee.com:chen-li-xing/c-sharp-object-oriented-notes.git
chen-li-xing
c-sharp-object-oriented-notes
C_sharp面向对象笔记
master

搜索帮助