⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 ASP.NET动态网站开发基础教程(C#)光盘素材的开发示例
💻 CS
字号:
using System;

namespace Inherit_Demo
{
	/// <summary>
	/// Class1 的摘要说明。
	/// </summary>
	class Class1
	{
		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			//
			// TODO: 在此处添加代码以启动应用程序
			//
			
			Rectangle rect = new Rectangle(0, 0, 20, 50);
			Square sqr = new Square(0, 0, 20, 50);
			rect.ShowArea();
			sqr.ShowArea();

			Console.WriteLine("\n\n按回车键退出");
			Console.ReadLine();
		}
	}

	
	class Rectangle 
	{
		public int left, top, width, height;
		protected string type;
     
		public Rectangle()
		{
			left = 0;
			top = 0;
			width = 10;
			height = 10;
			type = "矩形";
		}
    
		public Rectangle(int aLeft,int aTop, int aWidth,int aHeight)
		{
			left = aLeft;
			top = aTop;
			width = aWidth;
			height = aHeight;
			type = "矩形";
		}
    
		public void ShowArea()
		{
			Console.WriteLine("当前形状为{0}, 面积是{1}", 
				type, width*height);
		}
	}

	class Square : Rectangle
	{
		public Square():base() 
		{
			type = "正方形";
		}
    
		public Square(int aLeft,int aTop,int aWidth,int aHeight):this()
		{
			left = aLeft;
			top = aTop;
        
			//当宽和高不等时,去较小的值
			if (aWidth > aHeight) 
			{
				width = aHeight;
				height = aHeight;
			}
			else
			{
				width = aWidth;
				height = aWidth;
			}
		} 
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -