📄 program.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace Example10_10 {
class Program {
static void Main(string[] args) {
//创建Circle类变量circle
Circle circle = new Circle(35);
//分别调用两个Caculate方法
IShape shape = (IShape)circle;
shape.Caculate();
I2DShape shape2d = (I2DShape)circle;
shape2d.Caculate();
Console.ReadLine();
}
}
/// <summary>
/// IShape接口
/// </summary>
interface IShape {
/// <summary>
/// Area属性
/// </summary>
int Area {
get;
set;
}
/// <summary>
/// Caculate方法
/// </summary>
void Caculate();
}
interface I2DShape {
/// <summary>
/// Name属性
/// </summary>
string Name {
get;
set;
}
/// <summary>
/// Caculate方法
/// </summary>
void Caculate();
}
/// <summary>
/// Circle类继承IShape
/// </summary>
class Circle : IShape, I2DShape {
/// <summary>
/// area字段
/// </summary>
int area = 0;
/// <summary>
/// name字段
/// </summary>
string name = string.Empty;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="m_Area">m_Area参数</param>
public Circle(int m_Area) {
area = m_Area;
}
#region I2DShape 成员
/// <summary>
/// Name属性
/// </summary>
string I2DShape.Name {
get {
return name;
}
set {
name = value;
}
}
/// <summary>
/// Caculate方法
/// </summary>
void I2DShape.Caculate() {
Console.WriteLine("I2DShape的Caculate方法!");
}
#endregion
#region IShape 成员
/// <summary>
/// Area属性
/// </summary>
int IShape.Area {
get {
return area;
}
set {
area = value;
}
}
/// <summary>
/// Caculate方法
/// </summary>
void IShape.Caculate() {
Console.WriteLine("IShape的Caculate方法!");
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -