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

查看:89
本文介绍了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?)

推荐答案

在看看<一个href=\"http://blogs.msdn.com/ericlippert/archive/2007/05/14/why-are-overloaded-operators-always-static-in-c.aspx\">this帖子。

一个几个原因,主表面上的是到preserve操作者对称性(例如,一个二进制操作的左手侧没有得到特殊处理,如负责调度操作)。

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天全站免登陆