在这种情况下使用静态类 [英] In which case static class used

查看:101
本文介绍了在这种情况下使用静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪种情况下使用静态类我们使用其他原因?

In which case static class used we used other why?

推荐答案





有看看这里:

http:// stackoverflow.com/questions/241339/when-to-use-static-classes-in-c-sharp [ ^ ]

http://programmers.stackexchange.com/questions / 103914 / why-and-when-should-i-make-a-class-static-what-is-the-of-static-key [ ^ ]


we need static classes when we know that our class will not have any behavior as such. Suppose we have a set of helper or utility methods which we would like to wrap together in a class. Since these methods are generic in nature, we can define them all inside a static class. Remember that helper or utility methods need to be called many times, and since they are generic in nature, there is no need to create instances. E.g., suppose that you need a method that parses an int to a string. This method would come in the category of a utility or helper method.

So using the static keyword will make your code a bit faster since no object creation is involved.


这篇关于在这种情况下使用静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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