何时使用静态类和方法? [英] When to use static classes and methods?

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

问题描述

我有一个一般性的问题...什么时候应该使用静态类或静态方法? 我知道可以在不实例化的情况下调用静态方法的想法...并且静态类只应用于静态方法吗?...但是也存在性能方面的问题...在什么情况下应优先使用实例方法和课程?..如果有人可以简短地提及我什么时候应该选择使用它们以及什么时候应该避免使用它们?

I have a general question...when should i be using static classes or static methods?.. I know the idea that static methods can be called without instantiating...and static classes should only be used for static methods?...but are there any performance concerns also with it...and when should they be preferred over instance methods and classes?..If someone could just briefly mention when i should opt for using them and when i should avoid them?

推荐答案

我认为以下两个链接为您要查找的内容提供了明确的答案.看看他们:

I think the following two links offer a clear answer for what you're looking for. Take a look at them:

对于静态类:

何时在C#中使用静态类

对于静态方法:

何时适合使用静态方法?(乔恩·斯基特(Jon Skeet) [上师(Guru)回答了这个问题:o))

When is it appropriate to use static methods? ( Jon Skeet [the Guru] answered this one :o) )

这篇关于何时使用静态类和方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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