解释运算符重载 [英] Explain about operator overloading

查看:90
本文介绍了解释运算符重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都清楚地解释了运算符重载

anyone explain clearly about operator overloading

推荐答案

178,000 Google results for "C# operator overloading" [^]

The first page of results is rife with examples, tutorials, and explanations of the concept of operator overloading.


一种机制,针对用户定义的标准c#运算符赋予特殊含义诸如类或结构之类的数据类型称为操作者重载".

所有C#二进制运算符都可以重载.即+,-,*,/,%,&,|,<<>>.
所有C#unray运算符都可以重载.即+,_,!,++,-.
所有关系运算符都可以重载,但只能成对出现.即= =,!=,<> ;,< =,> =

简单来说,让我们说一下+是否超载

如果要找到+ b
如果a,b是整数,结果将是a和b的和,结果是整数.
如果a,b为浮点运算,则结果将为a和b的和,结果为浮点运算.
如果a,b是两个字符串,则结果将是String a和String b的串联,最终结果是string.

这样,+会根据数据进行不同的操作以使其超载.




您还可以推荐:
http://roque-patrick.com/windows/final/bbl0064.html [ ^ ]
The mechanism of giving a special meaning to a Standard c# operator with respect to a user defined data type such as classes or structures is known as OPERATOR OVERLOADING.

All C # binary operators can be over loaded. i.e +, - , *, / , %,&,|, <<,>>.
All C# unray operators can be over loaded. i.e +,_,!,++,-- .
All relational operators can be over loaded , but only as pairs. i.e = =, !=, <>, <=, >=

In simple terms let us say if + is overloaded

if you want to find a + b
if a,b are integer result will be sum of a and b and result is int.
if a,b are flot result will be sum of a and b and result is flot.
if a,b are two strings result will be concatenation of String a and String b and final result is string.

In this way + is overloaded with different operations depending up on the data.




u can also reffer:http://roque-patrick.com/windows/final/bbl0064.html[^]


请参见 [

这篇关于解释运算符重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆