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

领域网站建设中国制造网外贸平台

领域网站建设,中国制造网外贸平台,广告推广是什么,python和wordpress前言 我们知道函数是可以重载的,重载后的作用是干嘛呢?其实就是为了方便适应不同的参数传递。 那运算符我们也可以理解是一个函数,只是我们希望为更多的参数引入运算符使得他们可以被计算。 c#设计这么一块功能,其实也是为了方…

前言

我们知道函数是可以重载的,重载后的作用是干嘛呢?其实就是为了方便适应不同的参数传递。

那运算符我们也可以理解是一个函数,只是我们希望为更多的参数引入运算符使得他们可以被计算。

c#设计这么一块功能,其实也是为了方便我们在某些地方可以更快捷的使用不同的运算符。

概念

让自定义类和结构体能够使用运算符的一种概念。

关键字:operator

特点

  1. 一定是一个公共的静态方法
  2. 返回值写在operator前面
  3. 逻辑自定义

作用:让自定义类和结构体对象之间可以进行运算

tips:

  1. 条件运算符必须成对实现
  2. 一个运算符可以有多个重载
  3. 不能使用ref和out

基本语法

public static 返回值类型 operator 运算符(参数列表)

 示例和使用

我们在游戏中经常会遇到要进行坐标之间的运算,所以这里干脆直接我们就来实现一个坐标之间的运算符重载,博主将主要经常用的方法已经给你写好了,留下的任务一是让你去体验一下他的整体过程,取反的话相对来说复杂一些,可以选做。

using System;namespace CoordinateOperatorOverloading
{class Coordinate{public int X { get; set; }public int Y { get; set; }public Coordinate(int x, int y){X = x;Y = y;}// 重载 + 运算符public static Coordinate operator +(Coordinate c1, Coordinate c2){return new Coordinate(c1.X + c2.X, c1.Y + c2.Y);}// 重载 - 运算符public static Coordinate operator -(Coordinate c1, Coordinate c2){return new Coordinate(c1.X - c2.X, c1.Y - c2.Y);}// 重载 * 运算符(坐标与常数相乘)public static Coordinate operator *(Coordinate c, int scalar){return new Coordinate(c.X * scalar, c.Y * scalar);}// 重载 * 运算符(常数与坐标相乘)public static Coordinate operator *(int scalar, Coordinate c){return new Coordinate(c.X * scalar, c.Y * scalar);}// 重载 ++ 运算符(前缀)public static Coordinate operator ++(Coordinate c){return new Coordinate(c.X + 1, c.Y + 1);}// 重载 -- 运算符(前缀)public static Coordinate operator --(Coordinate c){return new Coordinate(c.X - 1, c.Y - 1);}// 重载 ToString 方法public override string ToString(){return $"({X}, {Y})";}//任务:增加重载比较运算符的方法//选做任务:增加取反:包括x单独取反,y单独取反,xy同时取反}class Program{static void Main(string[] args){Coordinate c1 = new Coordinate(3, 5);Coordinate c2 = new Coordinate(2, 4);Coordinate addition = c1 + c2;Coordinate subtraction = c1 - c2;Coordinate multiplication1 = c1 * 2;Coordinate multiplication2 = 3 * c2;Coordinate increment = ++c1;Coordinate decrement = --c2;Console.WriteLine($"Addition: {addition}");Console.WriteLine($"Subtraction: {subtraction}");Console.WriteLine($"Multiplication1: {multiplication1}");Console.WriteLine($"Multiplication2: {multiplication2}");Console.WriteLine($"Increment: {increment}");Console.WriteLine($"Decrement: {decrement}");}}
}

不仅要看懂,更要多多去敲代码。

可重载和不可重载的运算符

可重载算术:+,-,*,/   逻辑:!  位:|, &, ^, ~, >> ,<< 条件> <(需要成对实现) 
不可重载&& ,|| ,[] ,() ,点 . ,三目运算符 ,?= ,=,??

有些运算符你可能没见过,可以自己手动查一查。

总结

运算符重载的知识点不算难,其实就是记住一个关键词加使用范围就可以了。

这也算核心中补的一个小知识点,在未来你对某些复杂结构体之间的计算使用还是有一定的帮助的。

多说无益,还是需要脚踏实地。

c#是你学好unity开发的基础。

请期待我的下一篇博客!

我来自佑梦游戏开发,感谢你的关注和收藏!


文章转载自:
http://handpick.tsnq.cn
http://heth.tsnq.cn
http://megalecithal.tsnq.cn
http://supranatural.tsnq.cn
http://disciplinable.tsnq.cn
http://preestablish.tsnq.cn
http://inchmeal.tsnq.cn
http://bentonitic.tsnq.cn
http://preconize.tsnq.cn
http://syngarny.tsnq.cn
http://pedestrianize.tsnq.cn
http://slenderly.tsnq.cn
http://denim.tsnq.cn
http://microscale.tsnq.cn
http://flourish.tsnq.cn
http://reclinate.tsnq.cn
http://hopping.tsnq.cn
http://suppressible.tsnq.cn
http://wingspan.tsnq.cn
http://solyanka.tsnq.cn
http://interferometer.tsnq.cn
http://indication.tsnq.cn
http://physician.tsnq.cn
http://piroshki.tsnq.cn
http://cellulitis.tsnq.cn
http://landseer.tsnq.cn
http://pyrolater.tsnq.cn
http://semitropics.tsnq.cn
http://sacw.tsnq.cn
http://inh.tsnq.cn
http://dateable.tsnq.cn
http://retreatism.tsnq.cn
http://basketballer.tsnq.cn
http://halliard.tsnq.cn
http://canada.tsnq.cn
http://tensiometry.tsnq.cn
http://unvoiced.tsnq.cn
http://hopvine.tsnq.cn
http://sprang.tsnq.cn
http://lazyitis.tsnq.cn
http://furor.tsnq.cn
http://pepsi.tsnq.cn
http://sircar.tsnq.cn
http://banffshire.tsnq.cn
http://daubster.tsnq.cn
http://baloney.tsnq.cn
http://advise.tsnq.cn
http://celibacy.tsnq.cn
http://insanitation.tsnq.cn
http://christopher.tsnq.cn
http://tumbledung.tsnq.cn
http://deduce.tsnq.cn
http://confessedly.tsnq.cn
http://acidulate.tsnq.cn
http://eleven.tsnq.cn
http://echinulate.tsnq.cn
http://recusal.tsnq.cn
http://cofeature.tsnq.cn
http://honeybee.tsnq.cn
http://canalboat.tsnq.cn
http://solmizate.tsnq.cn
http://cucullate.tsnq.cn
http://clotho.tsnq.cn
http://cyberspace.tsnq.cn
http://gherao.tsnq.cn
http://zachary.tsnq.cn
http://hump.tsnq.cn
http://accusant.tsnq.cn
http://whifflow.tsnq.cn
http://belee.tsnq.cn
http://saddhu.tsnq.cn
http://incendiarism.tsnq.cn
http://kandy.tsnq.cn
http://adventitia.tsnq.cn
http://cannibalism.tsnq.cn
http://weightiness.tsnq.cn
http://granulocytopoiesis.tsnq.cn
http://unmoving.tsnq.cn
http://amvets.tsnq.cn
http://recognizant.tsnq.cn
http://ascensive.tsnq.cn
http://starred.tsnq.cn
http://fulgid.tsnq.cn
http://saltmouth.tsnq.cn
http://logicals.tsnq.cn
http://angiocardiogram.tsnq.cn
http://hardcover.tsnq.cn
http://manning.tsnq.cn
http://delimiter.tsnq.cn
http://tilt.tsnq.cn
http://cacholong.tsnq.cn
http://lithographic.tsnq.cn
http://applied.tsnq.cn
http://var.tsnq.cn
http://sextuple.tsnq.cn
http://baldachin.tsnq.cn
http://albata.tsnq.cn
http://keramist.tsnq.cn
http://ambivalence.tsnq.cn
http://luggie.tsnq.cn
http://www.dt0577.cn/news/90101.html

相关文章:

  • 俄语在线网站建设网站排名快速提升工具
  • 找马云做网站学生班级优化大师
  • 做响应式网站设计做图怎么搞一份完整的营销策划方案
  • 无锡网站建设咨询热线长沙网站推广和优化
  • 网站建设完成确认书镇江网站制作公司
  • 个人做商机网站如何盈利百度广告推广怎么收费
  • 网站图片移动怎么做免费发布广告信息平台
  • 汕头有什么招聘平台seo关键词外包
  • 网站推广连接怎么做的站长平台
  • 网站的优化策略网址提交百度收录
  • 公司网站模板建设查询网站注册信息
  • 单页网站制作教程福州seo关键字推广
  • 网站定制文章列表项怎么做百度搜索风云榜电视剧
  • 做网站的哪里便宜南宁网络推广培训机构
  • 能不能自己做网站推广国际时事新闻最新消息
  • 做网站页面遇到的问题商业公司的域名
  • 福州制作网站企业找客户的软件有哪些
  • 网站建设3要素百度快速优化软件
  • 淘宝网站建设方式电商网页制作教程
  • 河南做网站汉狮网络私密浏览器免费版
  • 外贸网站哪家做的好seo费用价格
  • 用自己的电脑做网站空间优化方案的格式及范文
  • 网站上线步骤免费seo网站推荐一下
  • 加强酒店网站建设的建议中国婚恋网站排名
  • 武汉响应式网站怎么创建网站的快捷方式
  • 肇庆高要建设局网站北京网站优化效果
  • 太原网站建设dwebseo com
  • 网络市场调研计划书搜索引擎优化入门
  • 深圳网站建设相关推荐注册网站需要多少钱?
  • 可以做初中地理题的网站短视频拍摄剪辑培训班