Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Bitmap is a seald class.why i can create instance.????while with The graphics are not??
Posted

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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Feb-11 0:49am    
Best answer so far, enough detail, my 5, proposed as a final answer.
--SA
Read some documentation.
sealed = cannot inherit from that class; can instantiate it, of course if it has a public constructor.
Graphics class does not have a public 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 from events...)
 
Share this answer
 
v2
Comments
Estys 12-Feb-11 4:50am    
a much better answer then mine.
Sergey Alexandrovich Kryukov 13-Feb-11 0:46am    
Correct explanation in principle, but the question is also about Bitmap, not only Graphics.
--SA
A sealed class cannot be inherited and it cannot be abstract.
So it definitely possible create a new instance.

Cheers
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Feb-11 0:47am    
Correct, my 4. Griff also added some rationale about Graphics and Bitmap, which is required by the question.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900