部分关键词在C#中实际使用 [英] Practical usage of partial keyword in C#

查看:102
本文介绍了部分关键词在C#中实际使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它可以让视觉工作室从UI事件分开的WinForms UI code等,但都没有任何实际用途呢?

I know it lets visual studio to separate WinForms UI code from the UI events, etc. But are there any practical uses for it?

推荐答案

partial关键字通常用于code发电设施,以允许开发者添加更多功能所产生的code,而不是$的恐惧C $ c。如果code再次产生被删除。

The partial keyword is typically used in code generation utilities to allow developers to add additional functionality to the generated code without the fear of that code being erased if the code is generated again.

使用C#3的部分关键词可以应用于方法,以允许产生code用户填写由发电机留下空白。在LINQ to SQL设计,例如提供部分方法,让您添加逻辑是,如果实施该框架将调用的类。这里的好处是,C#编译器将完全删除未实现部分的方法,所以没有性能损失的所有的不执行它们。

With C# 3 the partial keyword can be applied to methods to allow users of generated code to fill in blanks left by the generator. The Linq To Sql designer for example provides partial methods that allow you to add logic to the classes that the framework will call if implemented. The benefit here is that the C# compiler will completely remove unimplemented partial methods, so there is no performance hit at all for not implementing them.

部分类也可以用于组织非常大的班到单独的code文件,虽然这种用法通常是一个迹象,表明你的类过大,并承担太多的责任。

Partial classes can also be used to organize very large classes into separate code files, although this sort of usage is usually a sign that your classes are too large and are taking on too many responsibilities.

这篇关于部分关键词在C#中实际使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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