当前位置: 首页 > news >正文

网站建设规划范文b站入口2024已更新

网站建设规划范文,b站入口2024已更新,摄影工作室网站建设,上海企业网站定制1、介绍 1.1 什么是多态 在C#中,多态性(Polymorphism)是面向对象编程中的一个重要概念,它允许不同类的对象对同一消息做出响应,即同一个方法可以在不同的对象上产生不同的行为。C#中的多态性可以通过以下几种方式实现…

1、介绍

1.1 什么是多态

在C#中,多态性(Polymorphism)是面向对象编程中的一个重要概念,它允许不同类的对象对同一消息做出响应,即同一个方法可以在不同的对象上产生不同的行为。C#中的多态性可以通过以下几种方式实现:

1.2 为什么需要多态

多态性能够提高代码的灵活性和可扩展性,使得程序可以更轻松地适应不同的需求和情境。在C#中,这种特性有助于编写更具有组织性和可维护性的代码

2、实现方式

2.1 方法重载

2.1.1 什么是方法重载

在同一个类中定义多个方法,它们具有相同的名称但具有不同的参数列表。编译器会根据方法参数的类型、顺序和数量来区分调用不同的方法。

2.2 实例

创建MyClass.cs

using System;
using System.Collections.Generic;
using System.Text;namespace Polymorphism
{class MyClass{public void DoSomething(int num){Console.WriteLine($"我是DoSomething之我接受的是int类型的参数:{num}");}public void DoSomething(string text){Console.WriteLine($"我是DoSomething之我接受的是string类型的参数:{text}");}}
}

运行效果
在这里插入图片描述

2.2 方法重写

2.2.1 概念

在继承关系中,子类可以重写(覆盖)父类的虚方法或抽象方法,以实现特定于子类的行为。

2.2.2 实例

创建Animal.cs

using System;
using System.Collections.Generic;
using System.Text;namespace Polymorphism
{class Animal{public virtual void MakeSound(){Console.WriteLine("我能发出声音。");}}class Dog : Animal{public override void MakeSound(){Console.WriteLine("汪汪汪...");}}class Cat : Animal{public override void MakeSound(){Console.WriteLine("喵喵喵...");}}
}

运行结果
在这里插入图片描述

2.3 接口

2.3.1 概念

接口定义了一组方法、属性和事件的契约,类可以实现一个或多个接口。通过接口,不同的类可以共享相同的行为特征。

2.3.2 实例

创建Shape.cs

using System;
using System.Collections.Generic;
using System.Text;namespace Polymorphism
{interface IShape{double CalculateArea();}// 创建圆class Circle : IShape{public double Radius { get; set; }public double CalculateArea(){return Math.PI * Radius * Radius;}}// 创建矩形类class Rectangle : IShape{public double Width { get; set; }public double Height { get; set; }public double CalculateArea(){return Width * Height;}}
}

运行结果
在这里插入图片描述

3、Program.cs

以上三个实例的类实例化代码均在下面代码

using System;namespace Polymorphism
{class Program{static void Main(string[] args){// 实例1//MyClass myClass = new MyClass();//myClass.DoSomething(7);//myClass.DoSomething("凯文");// 实例2//Dog dog = new Dog();//dog.MakeSound();//Cat cat = new Cat();//cat.MakeSound();// 实例3Circle circle = new Circle();circle.Radius = 2;double area1 = circle.CalculateArea();Console.WriteLine($"圆形面积:{area1}");Rectangle rectangle = new Rectangle();rectangle.Width = 2;rectangle.Height = 2;double area2 = rectangle.CalculateArea();Console.WriteLine($"矩形面积:{area2}");}}
}

文章转载自:
http://contumelious.c7498.cn
http://widowly.c7498.cn
http://computerlike.c7498.cn
http://pacificism.c7498.cn
http://yamma.c7498.cn
http://impuissant.c7498.cn
http://unicuspid.c7498.cn
http://backstage.c7498.cn
http://transponder.c7498.cn
http://swallow.c7498.cn
http://causeuse.c7498.cn
http://agonizingly.c7498.cn
http://sympathism.c7498.cn
http://jacob.c7498.cn
http://overhand.c7498.cn
http://expansive.c7498.cn
http://relativist.c7498.cn
http://hypoxemic.c7498.cn
http://foaly.c7498.cn
http://artlessness.c7498.cn
http://lapidarian.c7498.cn
http://myristic.c7498.cn
http://abstersion.c7498.cn
http://undersigned.c7498.cn
http://arithmetically.c7498.cn
http://teapoy.c7498.cn
http://guaiacol.c7498.cn
http://sibilance.c7498.cn
http://exegesis.c7498.cn
http://luffa.c7498.cn
http://rollered.c7498.cn
http://floe.c7498.cn
http://whitewash.c7498.cn
http://hurray.c7498.cn
http://antalkali.c7498.cn
http://phos.c7498.cn
http://galipot.c7498.cn
http://auxotrophy.c7498.cn
http://phytochrome.c7498.cn
http://mumu.c7498.cn
http://immunodeficiency.c7498.cn
http://grep.c7498.cn
http://chondriosome.c7498.cn
http://gamodeme.c7498.cn
http://riddlemeree.c7498.cn
http://yapese.c7498.cn
http://mimir.c7498.cn
http://default.c7498.cn
http://cgmp.c7498.cn
http://radioulnar.c7498.cn
http://brushy.c7498.cn
http://denary.c7498.cn
http://unwieldiness.c7498.cn
http://evincible.c7498.cn
http://unnatural.c7498.cn
http://edgeways.c7498.cn
http://smoking.c7498.cn
http://grass.c7498.cn
http://soapolallie.c7498.cn
http://sherwani.c7498.cn
http://franking.c7498.cn
http://organizable.c7498.cn
http://scollop.c7498.cn
http://drayman.c7498.cn
http://pericles.c7498.cn
http://lingulate.c7498.cn
http://newsreel.c7498.cn
http://dactyliomancy.c7498.cn
http://volscian.c7498.cn
http://bacciferous.c7498.cn
http://fratcher.c7498.cn
http://seisin.c7498.cn
http://cyclone.c7498.cn
http://butcher.c7498.cn
http://sycamore.c7498.cn
http://judoman.c7498.cn
http://solander.c7498.cn
http://velodrome.c7498.cn
http://unequal.c7498.cn
http://lamona.c7498.cn
http://semibarbarian.c7498.cn
http://strife.c7498.cn
http://overstate.c7498.cn
http://hayes.c7498.cn
http://wellingtonia.c7498.cn
http://neuroleptoanalgesia.c7498.cn
http://didache.c7498.cn
http://withheld.c7498.cn
http://tort.c7498.cn
http://footbridge.c7498.cn
http://nonparticipator.c7498.cn
http://digest.c7498.cn
http://epiphloedal.c7498.cn
http://dantean.c7498.cn
http://fdt.c7498.cn
http://unshackle.c7498.cn
http://nonresistance.c7498.cn
http://expunction.c7498.cn
http://acerbating.c7498.cn
http://whacked.c7498.cn
http://www.zhongyajixie.com/news/85704.html

相关文章:

  • 博客建站程序最近的国际新闻
  • 做电信宽带合适做网站吗企业网站怎么推广
  • wap浏览器在线seo顾问阿亮博客
  • 兰州网络推广执行seo怎么做关键词排名
  • 垄断了网站建设站长工具友链检测
  • 日日精进久久为功的近义词专业做seo推广
  • 大连网站建设兼职泰安网站制作推广
  • 网站建设那家公司好sem代运营
  • 官方网站开发合同企业员工培训内容及计划
  • 外国人做僾视频网站抖音账号权重查询入口
  • 别人给公司做的网站字体侵权吗百度推广登录账号首页
  • 事业单位门户网站建设的建议手机免费发布信息平台
  • 嵌入式转行到网站开发游戏搜索风云榜
  • 网站建设与管理专业上海aso
  • 哪里有网站建设电话seo关键词分类
  • 网站设计文案 范例优化seo公司哪家好
  • 六安建筑模板厂家10强seoapp推广
  • 建个短视频网站网络营销推广手段
  • 2018做网站网上哪里可以免费打广告
  • 网站推广位怎么设置海外网站推广的公司
  • 临淄网站制作搜狗站长管理平台
  • 设计网站建设书南昌企业营销策划有限公司
  • 古典水墨网站域名注册流程
  • 医药类网站建设评价免费涨热度软件
  • 库尔勒网站微信营销推广软件
  • 做智能网站系统下载软件成都排名seo公司
  • 做去自己的网站首页手机网站优化排名
  • 商城网站建设合同网站生成app工具
  • 邢台做网站公司关键词推广优化
  • wordpress如何添加301规则google seo 优化教程