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. how can we write large source code in 2 or more seperate units?

how can we write large source code in 2 or more seperate units?

Scheduled Pinned Locked Moved C#
questioncsharpdelphitutorial
21 Posts 8 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.
  • P PIEBALDconsult

    John Simmons / outlaw programmer wrote:

    you have to include htis line

    No you don't, but he will need a reference.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #9

    PIEBALDconsult wrote:

    No you don't, but he will need a reference.

    Actually, both a reference to the asembly and the using statment.

    P 1 Reply Last reply
    0
    • L Lost User

      PIEBALDconsult wrote:

      No you don't, but he will need a reference.

      Actually, both a reference to the asembly and the using statment.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #10

      Shameel wrote:

      the using statment

      Is not required and only weak developers use them.

      L J 2 Replies Last reply
      0
      • P PIEBALDconsult

        Shameel wrote:

        the using statment

        Is not required and only weak developers use them.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #11

        PIEBALDconsult wrote:

        not required

        Technically, yes. But this code

        using Com.Company.Suite.Product.Version.Module;

        MyClass c1 = new MyClass();

        is more readable by an order of magnitude than this code

        Com.Company.Suite.Product.Version.Module.MyClass c1 = new Com.Company.Suite.Product.Version.Module.MyClass();

        P 1 Reply Last reply
        0
        • F Fred 34

          when a program becomes very big in source code, its better to write it within 2 or more seperate source code and then compile them together. question is this thah how can we do it in C#? and how tow to combine it to other routines. in delphi we do it by units, but I am novice in c#. please tell me step by step and explicit. tnx

          B Offline
          B Offline
          BillWoodruff
          wrote on last edited by
          #12

          I think another way to "frame" this question ... if my intuition is on-line here ... is to ask: how can I design, or re-design, my getting-very-big project into functional units, or: how can I determine a set of "organic criteria" which to use as an "organizing principle" to divide my project into logical "chunks" which, in the long run, contribute to program extension, maintenance, and de-bugging (and lend themselves to unit-testing in "isolation" ?). All the "tools" mentioned here, including "Partial Classes," "Class Libraries," etc. are valuable. ... edit in appreciative response to feedback from PiebaldConsult ... Please note: in Visual Studio the option to create a "Class Library" is one that appears when you create a new Solution, and also appears as an option when you choose to add a "New Project" to an existing "Solution." The question of whether a "Solution," which "begins life" as "only" a "Class Library," is, semantically, a "Solution," or a "Project" ... we'll we won't touch that one ... :) ... end edit ... You create it, compile it, and, then, to use it "externally," you must reference it, by adding a Reference to the compiled .dll via the Solution Explorer/ References / Add Reference facility. The location of that compiled .dll can be anywhere: and the Add Reference dialog will let you browse to find it. Once the Reference is added: you do not need to have a 'using' statement for it to be accessed. The one "tool," not mentioned here, that may also be useful in "encapsulating functional units," is using NameSpaces: within one solution you can add Classes, etc., and encapsulate them in the scope of a different NameSpace. In that case, to access the "whatever inside" that NameSpace, you will need to have a "using" statement in your Form or whatever it is that requires access. Or, you can avoid having a "using," statement kby using a "fully qualified" reference: Example:

          using SpecialNameSpace;

          // now you can reference a class in SpecialNameSpace directly:

          SpecialClass theSpecialClass = new SpecialClass();

          // or ... without the "using" statement:

          SpecialNameSpace.SpecialClass theSpecialClass = new SpecialNameSpace.SpecialClass();

          However, when your solution, with multiple NameSpaces, is compiled, the resulting .exe incorporates everything: no separate files are created just by using different NameSpaces. I have never experimented with trying to import a compiled class library dll into another class library, but,

          P 1 Reply Last reply
          0
          • L Lost User

            PIEBALDconsult wrote:

            not required

            Technically, yes. But this code

            using Com.Company.Suite.Product.Version.Module;

            MyClass c1 = new MyClass();

            is more readable by an order of magnitude than this code

            Com.Company.Suite.Product.Version.Module.MyClass c1 = new Com.Company.Suite.Product.Version.Module.MyClass();

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #13

            Shameel wrote:

            is more readable

            I disagree, especially when code snippets are published here.

            realJSOPR L 2 Replies Last reply
            0
            • B BillWoodruff

              I think another way to "frame" this question ... if my intuition is on-line here ... is to ask: how can I design, or re-design, my getting-very-big project into functional units, or: how can I determine a set of "organic criteria" which to use as an "organizing principle" to divide my project into logical "chunks" which, in the long run, contribute to program extension, maintenance, and de-bugging (and lend themselves to unit-testing in "isolation" ?). All the "tools" mentioned here, including "Partial Classes," "Class Libraries," etc. are valuable. ... edit in appreciative response to feedback from PiebaldConsult ... Please note: in Visual Studio the option to create a "Class Library" is one that appears when you create a new Solution, and also appears as an option when you choose to add a "New Project" to an existing "Solution." The question of whether a "Solution," which "begins life" as "only" a "Class Library," is, semantically, a "Solution," or a "Project" ... we'll we won't touch that one ... :) ... end edit ... You create it, compile it, and, then, to use it "externally," you must reference it, by adding a Reference to the compiled .dll via the Solution Explorer/ References / Add Reference facility. The location of that compiled .dll can be anywhere: and the Add Reference dialog will let you browse to find it. Once the Reference is added: you do not need to have a 'using' statement for it to be accessed. The one "tool," not mentioned here, that may also be useful in "encapsulating functional units," is using NameSpaces: within one solution you can add Classes, etc., and encapsulate them in the scope of a different NameSpace. In that case, to access the "whatever inside" that NameSpace, you will need to have a "using" statement in your Form or whatever it is that requires access. Or, you can avoid having a "using," statement kby using a "fully qualified" reference: Example:

              using SpecialNameSpace;

              // now you can reference a class in SpecialNameSpace directly:

              SpecialClass theSpecialClass = new SpecialClass();

              // or ... without the "using" statement:

              SpecialNameSpace.SpecialClass theSpecialClass = new SpecialNameSpace.SpecialClass();

              However, when your solution, with multiple NameSpaces, is compiled, the resulting .exe incorporates everything: no separate files are created just by using different NameSpaces. I have never experimented with trying to import a compiled class library dll into another class library, but,

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #14

              BillWoodruff wrote:

              it is a type of Solution

              It is a type of project. A solution may contain many projects of various types. And you can add a project of class library type to an existing solution.

              B 1 Reply Last reply
              0
              • P PIEBALDconsult

                BillWoodruff wrote:

                it is a type of Solution

                It is a type of project. A solution may contain many projects of various types. And you can add a project of class library type to an existing solution.

                B Offline
                B Offline
                BillWoodruff
                wrote on last edited by
                #15

                +5 Absolutely correct: interestingly, I've never created a Class Library that way. I have edited my response to incorporate your feedback, thanks. best, Bill

                "It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle

                realJSOPR 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Shameel wrote:

                  is more readable

                  I disagree, especially when code snippets are published here.

                  realJSOPR Offline
                  realJSOPR Offline
                  realJSOP
                  wrote on last edited by
                  #16

                  Code snippets with references to 3rd-party/programmer-created namespaces is kinda pointless anyway. And who are you calling weak? :)

                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                  -----
                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                  -----
                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                  1 Reply Last reply
                  0
                  • B BillWoodruff

                    +5 Absolutely correct: interestingly, I've never created a Class Library that way. I have edited my response to incorporate your feedback, thanks. best, Bill

                    "It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle

                    realJSOPR Offline
                    realJSOPR Offline
                    realJSOP
                    wrote on last edited by
                    #17

                    YOU'RE WEAK! :)

                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                    -----
                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                    -----
                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                    B 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Shameel wrote:

                      is more readable

                      I disagree, especially when code snippets are published here.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #18

                      PIEBALDconsult wrote:

                      I disagree, especially when code snippets are published here.

                      Well, the vast majority of code that we write goes into some commercial project rather than CP posts. Repeating the fully qualified type name of class everywhere it is used makes no sense especially when VS (and SD for that matter) tell you the fully qualified type name just by hovering the mouse over it.

                      P 1 Reply Last reply
                      0
                      • L Lost User

                        PIEBALDconsult wrote:

                        I disagree, especially when code snippets are published here.

                        Well, the vast majority of code that we write goes into some commercial project rather than CP posts. Repeating the fully qualified type name of class everywhere it is used makes no sense especially when VS (and SD for that matter) tell you the fully qualified type name just by hovering the mouse over it.

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #19

                        Shameel wrote:

                        the vast majority of code that we write goes into some commercial project rather than CP posts

                        Yet the vast majority of code I see that I didn't write is in CP posts.

                        Shameel wrote:

                        VS (and SD

                        Which I don't use if I can avoid it. I also prefer to print out code so I can review it away from the computer.

                        1 Reply Last reply
                        0
                        • realJSOPR realJSOP

                          YOU'RE WEAK! :)

                          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                          -----
                          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                          -----
                          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

                          B Offline
                          B Offline
                          BillWoodruff
                          wrote on last edited by
                          #20

                          “Keep me away from the wisdom which does not cry, the philosophy which does not laugh and the greatness which does not bow before children.” Kahlil Gibran Happy Holidays, John ! :) best, Bill

                          "It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle

                          1 Reply Last reply
                          0
                          • P PIEBALDconsult

                            Shameel wrote:

                            the using statment

                            Is not required and only weak developers use them.

                            J Offline
                            J Offline
                            Jan Steyn
                            wrote on last edited by
                            #21

                            Agree 100%. Always use the full name.

                            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