Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Inherit an internal class to a public class

Inherit an internal class to a public class

Scheduled Pinned Locked Moved C#
csharp
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A amit sahu20

    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

    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #5

    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 OriginalGriffO 2 Replies Last reply
    0
    • L Luc Pattyn

      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 Offline
      A Offline
      amit sahu20
      wrote on last edited by
      #6

      thanx

      1 Reply Last reply
      0
      • L Luc Pattyn

        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.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #7

        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.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        L 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          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.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #8

          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.

          OriginalGriffO 2 Replies Last reply
          0
          • L Luc Pattyn

            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.

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #9

            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.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            L D 2 Replies Last reply
            0
            • L Luc Pattyn

              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.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #10

              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.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              L 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                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.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #11

                :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.

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  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.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #12

                  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.

                  1 Reply Last reply
                  0
                  • A amit sahu20

                    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

                    L Offline
                    L Offline
                    Lukasz Nowakowski
                    wrote on last edited by
                    #13

                    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.

                    1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      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.

                      D Offline
                      D Offline
                      dave dolan
                      wrote on last edited by
                      #14

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups