什么是使用静态类的 [英] What is the use of a static class
问题描述
什么是使用静态类的? 我的意思是使用静态类,以及如何使用CLR静态类交易的好处是什么?
What is the use of a static class? I mean what are benefits of using static class and how CLR deals with static classes?
推荐答案
静态类只是表示您不希望或需要的实例的。这是实用的逻辑,其中code不特定对象有用。例如,扩展方法可以的只有的写在一个静态类。
A static class simply denotes that you don't expect or need an instance. This is useful for utility logic, where the code is not object-specific. For example, extension methods can only be written in a static class.
pre C#2.0中,你可以只是一个普通类与私有构造函数;但静态
使正规的,你可以的永远的有一个实例(也就是否构造函数*,并且所有成员必须是静态的)。
Pre C# 2.0, you could just have a regular class with a private constructor; but static
makes it formal the you can never have an instance (there is no constructor*, and all members must be static).
(* =见注释链,你可以有一个类型初始化(静态构造函数又名 .cctor
),但你不能有实例构造函数(又名 .ctor
))。
(*=see comment chain; you can optionally have a type initializer (static constructor aka .cctor
), but you cannot have an instance constructor (aka .ctor
)).
这篇关于什么是使用静态类的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!