Inherit an internal class to a public class
-
thanx, yup, i tried and got error msg. Then pls let me know, what will be the use of internal class in class library(any real time eg) mean signification reason of using internal class in class library
a class can be useful without being inherited; so could be a nested class, however an internal one is usable in several classes within the same source file. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
a class can be useful without being inherited; so could be a nested class, however an internal one is usable in several classes within the same source file. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
thanx
-
a class can be useful without being inherited; so could be a nested class, however an internal one is usable in several classes within the same source file. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
That's not strictly true, Luc: internal classes are available within the same namespace rather than file. I frequently use internal for sub forms which are useful within the context of my public classes in a namespace, but which would be confusing or useless outside. BTW: How did/is the chess go/going?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
That's not strictly true, Luc: internal classes are available within the same namespace rather than file. I frequently use internal for sub forms which are useful within the context of my public classes in a namespace, but which would be confusing or useless outside. BTW: How did/is the chess go/going?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
you are right, some people may put more than one namespace in a file, I know I wouldn't. BTW: it is much too early to tell, preliminary battles yielded a typical 50%, however it is a 9-day open encounter according to the Swiss[^] pairing system. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
you are right, some people may put more than one namespace in a file, I know I wouldn't. BTW: it is much too early to tell, preliminary battles yielded a typical 50%, however it is a 9-day open encounter according to the Swiss[^] pairing system. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
some people may put more than one namespace in a file
Yeuch! No, no, no! Don't do it! One class, one file. One namespace, many files. Internal is not restricted to file, just to namespace.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
you are right, some people may put more than one namespace in a file, I know I wouldn't. BTW: it is much too early to tell, preliminary battles yielded a typical 50%, however it is a 9-day open encounter according to the Swiss[^] pairing system. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Hang on, I've just realised - by file you are referring to Assembly (DLL/EXE) where I am referring to source. Oops! But I agree - one assembly, one namespace.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Luc Pattyn wrote:
some people may put more than one namespace in a file
Yeuch! No, no, no! Don't do it! One class, one file. One namespace, many files. Internal is not restricted to file, just to namespace.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
:thumbsup:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hang on, I've just realised - by file you are referring to Assembly (DLL/EXE) where I am referring to source. Oops! But I agree - one assembly, one namespace.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
you should have left it at that. I did say source file, not assembly. :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
thanx, yup, i tried and got error msg. Then pls let me know, what will be the use of internal class in class library(any real time eg) mean signification reason of using internal class in class library
Internal class is visible only inside assembly. You can use it to implement functionality, that is required by your assembly, but shouldn't be accessible outside the assembly. The real life example you say... Let's say your application has an assembly for accessing database. You have classes with methods that perform some operations on database (insert, update, delete, select). Under the hood you use Entity Framework, but to assure, that database access is performed only with your classes, you set Entity Framework context class as internal. That provides you with cleaner code and strict separation of layers - higher layers don't know what mechanism you use for accessing database... and honestly, they shouldn't care.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
-
Luc Pattyn wrote:
some people may put more than one namespace in a file
Yeuch! No, no, no! Don't do it! One class, one file. One namespace, many files. Internal is not restricted to file, just to namespace.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Assembly AND namespace. You cannot use someone else's internal classes by simply adding your own version of that namespace in your own assembly. The whole idea is to make it so that ONLY the guy who wrote the original method can decide how to use it. Not so that only people who know what namespace it is can use it. This is basic .net 101, and has been true since version 1.0. edit: one more qualification, this applies to 'internal' classes that do not specify the 'internal' modifier. If you specify the 'internal' modifier you can use them within any namespace as long as you reference the correct one, but STILL only within the original assembly. So for example a class declared as class MyClass(){ } can only be referenced in its original namespace and assembly. However, one declared as internal class MyClass() { } can be referenced by anything in the assembly.