为什么 C# 运算符重载必须是静态的? [英] Why must C# operator overloads be static?

查看:21
本文介绍了为什么 C# 运算符重载必须是静态的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 C# 要求运算符重载是静态方法而不是成员函数(如 C++)?(也许更具体地说:这个决定的设计动机是什么?)

Why does C# require operator overloads to be static methods rather than member functions (like C++)? (Perhaps more specifically: what was the design motivation for this decision?)

推荐答案

看看 这篇文章.

有几个原因,主要似乎是为了保持运算符的对称性(这样二元运算的左侧不会得到特殊处理,因为它负责调度操作).

A couple of reasons, the primary seeming to be to preserve operator symmetry (such that the left hand side of a binary operation does not get special treatment, as being responsible for dispatching the operation).

这篇关于为什么 C# 运算符重载必须是静态的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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