• 大小: 29KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-17
  • 语言: C#
  • 标签: 继承  封装  多态  示例  

资源简介

用一个示例来说明C#中的继承、封装和多态,希望对于刚学C#语言的朋友们理解继承、封装和多态有一定的帮助作用吧

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InheriteDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //Shape triangle = new Triangle(345);
            //triangle.PrintArea();
            //triangle.PrintPerimeter();

            //Shape circle = new Circle(10);
            //circle.PrintArea();
            //circle.PrintPerimeter();
            //Console.ReadKey();
            Shape[] shapes = new Shape[]
            {
               new Circle(10)
               new Circle(8)
               new Circle(100)
               new Triangle(345)
               new Triangle(101010)
               new Triangle(81012)
            };
            foreach (Shape shape in shapes)
            {
                shape.PrintArea();
                shape.PrintPerimeter();
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       7168  2012-01-06 10:37  InheriteDemo\InheriteDemo\bin\Debug\InheriteDemo.exe

     文件      22016  2012-01-06 10:37  InheriteDemo\InheriteDemo\bin\Debug\InheriteDemo.pdb

     文件      11600  2012-01-06 10:37  InheriteDemo\InheriteDemo\bin\Debug\InheriteDemo.vshost.exe

     文件        490  2010-03-17 22:39  InheriteDemo\InheriteDemo\bin\Debug\InheriteDemo.vshost.exe.manifest

     文件       2481  2012-01-06 09:53  InheriteDemo\InheriteDemo\InheriteDemo.csproj

     文件       5800  2012-01-06 10:37  InheriteDemo\InheriteDemo\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        401  2012-01-06 10:37  InheriteDemo\InheriteDemo\obj\x86\Debug\InheriteDemo.csproj.FileListAbsolute.txt

     文件       7168  2012-01-06 10:37  InheriteDemo\InheriteDemo\obj\x86\Debug\InheriteDemo.exe

     文件      22016  2012-01-06 10:37  InheriteDemo\InheriteDemo\obj\x86\Debug\InheriteDemo.pdb

     文件       1016  2012-01-06 10:37  InheriteDemo\InheriteDemo\Program.cs

     文件       1356  2012-01-06 09:01  InheriteDemo\InheriteDemo\Properties\AssemblyInfo.cs

     文件       6619  2012-01-06 11:45  InheriteDemo\InheriteDemo\Shape.cs

     文件        878  2012-01-06 09:01  InheriteDemo\InheriteDemo.sln

    ..A..H.     16384  2012-01-06 10:37  InheriteDemo\InheriteDemo.suo

     目录          0  2012-01-06 09:01  InheriteDemo\InheriteDemo\obj\x86\Debug\TempPE

     目录          0  2012-01-06 10:37  InheriteDemo\InheriteDemo\obj\x86\Debug

     目录          0  2012-01-06 09:55  InheriteDemo\InheriteDemo\bin\Debug

     目录          0  2012-01-06 09:01  InheriteDemo\InheriteDemo\obj\x86

     目录          0  2012-01-06 09:01  InheriteDemo\InheriteDemo\bin

     目录          0  2012-01-06 09:01  InheriteDemo\InheriteDemo\obj

     目录          0  2012-01-06 09:01  InheriteDemo\InheriteDemo\Properties

     目录          0  2012-01-06 09:02  InheriteDemo\InheriteDemo

     目录          0  2012-01-06 09:01  InheriteDemo

----------- ---------  ---------- -----  ----

               105393                    23


评论

共有 条评论