问题描述
我正在努力理解将一个类定义为''静态''对我来说是什么。
这是一个例子,因为也许我在想这一切都错了:
我的应用程序将允许用户控制应用程序使用的字体。
所以我需要根据用户
输入的设置更改字体。但是,对于我来说,使用
注册表,获取字体信息并为我要显示的每个表单创建新的字体对象似乎都是浪费。所以我想也许
''static''关键字以某种方式保住了我的救赎。我想要一个
clas从注册表中读取,创建字体,然后他们
是否有任何表格可供参考。 />
对此的任何评论都将不胜感激。
谢谢,
-Neil K.
I''m trying to understand what defining a class as ''static'' does for
me.
Here''s an example, because maybe I am thinking about this all wrong:
My app will allows the user to control the fonts that the app uses.
So I will need to change the fonts depending on what settings the user
has entered. However, it seems kind of wasteful to me to go to teh
registry, fetch the font information and create new font objects for
every form that I am going to display. So I was thinking that perhaps
the ''static'' keyword held my salvation somehow. I''d like to have a
clas that reads from the registry, creates the fonts, and then they
are there for any of the forms to reference.
Any comments on that would be greatly appreciated.
Thanks,
-Neil K.
推荐答案
从技术上来说,如果OP使用C#2(因为快递产品
beta出现了,可能性就在那里)。 C#2中的静态类只是
类,它们只能拥有静态成员并且可以自动化密封
模式,你可以用于纯静态类。
然而,在这个边缘情况下,答案的其余部分是完全有效的,那就是为了避免混淆(并且可能会创建一些,;)。
只是一种技术性问题。 />
Technically there is, if the OP was using C# 2(since the express product
betas came out, the possiblity is there). Static classes in C# 2 are simply
classes that can only have static members and that automate the sealing
pattern you ahve to use for a pure static class.
However, in that edge case, the rest of the answer is perfectly valid, thats
just a technicality to avoid confusion(And probably create some, ;).
---
接收邮件已通过无病毒认证。
由AVG反病毒系统检查(。
版本:6.0.771 /病毒库:518 - 发布日期:28/09/2004
[microsoft.public.dotnet.languages.csharp]
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004
[microsoft.public.dotnet.languages.csharp]
这篇关于关于“静态类”的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!