扩展方法在C#中的任何限制

编程入门 行业动态 更新时间:2024-10-11 07:31:58
本文介绍了扩展方法在C#中的任何限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要问,不添加扩展方法,数据类型的作品以同样的方式为微软的方法或没有任何可以limitaion。

这是有关经验的程序员谁了,而使用他们找一些限制。

解决方案

什么样的限制是怎么想的?我并不特别喜欢他们发现的方式 - 以及特别的方式,如果扩展类型后获得具有相同签名的方法,将静默与周围的扩展方法根本没有警告称为

有一些方法,使他们不工作,以及人们所喜欢的 - 例如,的你不能写一个委托类型和呼叫扩展方法它直接在lambda表达式或匿名方法 - 但这是不够合理的。

除此之外,我不知道有显著的局限性 - 我当然避风港T在哪里见过微软的源代码已经有大约扩展方法适用的特殊规则的任何情况。

您最后一句话使得它听起来像你的有无的看到了一些限制 - ?你能与我们分享

I want to ask, does adding extension methods to datatypes works in the same way as Microsoft's methods or do they have any limitaion.

This is relevant to experienced programmers who had find some limitations while using them.

解决方案

What sort of limitations are you thinking of? I'm not particularly fond of the way they're discovered - and in particular, the way that if the extended type later gains a method with the same signature, that will silently be called with no warnings around the extension method at all.

There are some ways in which they don't work as well as one might like - for example, you can't write an extension method for a delegate type and call it directly on a lambda expression or anonymous method - but that's reasonable enough.

Beyond that, I'm not aware of significant limitations - and I certainly haven't seen any situations where Microsoft code has had special rules applied around extension methods.

Your last sentence makes it sound like you have seen some limitations - could you share them with us?

更多推荐

扩展方法在C#中的任何限制

本文发布于:2023-11-12 10:00:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!