为什么我们可以创建位图实例 [英] why we could create instance of bitmap
本文介绍了为什么我们可以创建位图实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
位图是一个密封的类.为什么我可以创建实例.??而没有图形?
Bitmap is a seald class.why i can create instance.????while with The graphics are not??
推荐答案
密封并不意味着您不能使用它:这意味着您不能从中继承.
您可以创建任何未标记为静态的类的实例:由于C#没有全局变量的概念,因此无法实例化的类将不可用.
为什么位图是密封类?可能是为了阻止人们添加它,并期望这些添加在位图文件中起作用.鉴于位图文件的格式是固定的,这将是有道理的.
另一方面,Graphics对象不是密封的:您可以继承它并对其进行增强.如果所需的draw方法不存在,那么至少可以添加功能.
Sealed does not mean you cannot use it: it means that you cannot inherit from it.
You can create an instance of any class that is not marked static: Since C# has no concept of global variables, a class that you could not instantiate would not be usable.
Why is Bitmap a sealed class? Probably to stop people adding to it and expecting the additions to work in the bitmap file. Given that the format of a Bitmap file is fixed, that would make sense.
The Graphics object on the other hand is not sealed: you can inherit from it and enhance it. That at least allows for facilities to be added if the required draw method does not exist.
阅读一些文档.
sealed
=不能从该class
继承;可以实例化它,当然,如果它具有public
构造函数.
Graphics
class
没有public
构造函数.这就是为什么您不能以这种方式实例化它的原因.但是,您可以通过其他方式(static
方法,e.Graphics
的e.Graphics
...)创建它的实例
Read some documentation.
sealed
= cannot inherit from thatclass
; can instantiate it, of course if it has apublic
constructor.
Graphics
class
does not have apublic
constructor. That''s why you can''t instantiate it that way. You can however create an instance of it through other means (static
methods,e.Graphics
fromevent
s...)
不能继承<<密封的类,并且不能是抽象的.
因此,绝对有可能创建一个新实例.
干杯
A sealed class cannot be inherited and it cannot be abstract.
So it definitely possible create a new instance.
Cheers
这篇关于为什么我们可以创建位图实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文