Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i am working in a project and i want to stop the class being inherited..
Posted 30-Dec-12 21:31pm
Comments
Sergey Alexandrovich Kryukov at 2-Jan-13 23:22pm
   
Please: 1) stop posting non-question in this forum, called "Quick Questions & Answers", 2) do not post your comments and other text as "solutions".
 
Doing so can hardly help you, but may only cause some down-votes and abuse reports, unpleasant things you don't want.
 
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Mark it as sealed[^]
 
public sealed class myClass : myBase {...}
  Permalink  
Comments
__TR__ at 31-Dec-12 4:59am
   
This answer doesn't deserve a 1. Countered.
Sergey Alexandrovich Kryukov at 2-Jan-13 23:23pm
   
Agree, a 5.
—SA
Marcus Kramer at 9-Jan-13 16:07pm
   
+5. Of course.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

by putting "Sealed" keyword, you can achieve your target. sealed keyword do not let any class to be inherited by other class.
I would also suggest you to please first learn access specifiers and then do start programming other wise, you structure will begun dangling at some place.
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 2-Jan-13 23:25pm
   
Your second clause is really valuable. But the first one is merely a mistake. You make class concrete it it is non-abstract. Sealed is not related to concreteness/abstractness.
—SA
Faisalabadians at 3-Jan-13 1:22am
   
I said concrete in sense of c++, there is the concept for concrete instead of sealed. I know, it should not be said.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You can create it as Sealed class. Sealed class cannot be inherited.
Ex.
public sealed class yourClass {..}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Make it a sealed class when writing the class. sealed a keyword used when you want to just initialize the class and use the object and do not want any other class to inherit it.
 
For Examples:
 
public sealed MyClass
{
    //Class members
}
  Permalink  

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

  Print Answers RSS
0 CPallini 550
1 Sergey Alexandrovich Kryukov 420
2 George Jonsson 288
3 Pheonyx 218
4 OriginalGriff 200
0 OriginalGriff 4,813
1 CPallini 3,850
2 Sergey Alexandrovich Kryukov 3,224
3 George Jonsson 2,552
4 Gihan Liyanage 2,186


Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100