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. Writing source code in seperate files

Writing source code in seperate files

Scheduled Pinned Locked Moved C#
15 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.
  • F Offline
    F Offline
    Fred 34
    wrote on last edited by
    #1

    How can we write the long source of a program in 2 or 3 files and relate them together at build time.

    L D J B 5 Replies Last reply
    0
    • F Fred 34

      How can we write the long source of a program in 2 or 3 files and relate them together at build time.

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

      Use Partial Classes[^].

      Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

      L 1 Reply Last reply
      0
      • F Fred 34

        How can we write the long source of a program in 2 or 3 files and relate them together at build time.

        D Offline
        D Offline
        Dean Oliver
        wrote on last edited by
        #3

        If you referring to writing classes with an extensive amount of code. Then I'd suggest you use the "partial" key word. That way you can spread your class over separate files. In each file you just call the full declaration of the class but with the partial key word. Eg;

        public partial class Employee
        {
        public void DoWork()
        {
        }
        }

        public partial class Employee
        {
        public void GoToLunch()
        {
        }
        }

        http://msdn.microsoft.com/en-us/library/wa80x488%28v=vs.80%29.aspx[^]

        1 Reply Last reply
        0
        • L Lost User

          Use Partial Classes[^].

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

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

          I rather think he has five source-files (.cs) that should be linked to a single executable. The IDE does that for us :)

          Bastard Programmer from Hell :suss:

          L 1 Reply Last reply
          0
          • L Lost User

            I rather think he has five source-files (.cs) that should be linked to a single executable. The IDE does that for us :)

            Bastard Programmer from Hell :suss:

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

            The question (as with so many) is somewhat open to interpretation. :(

            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

            L 1 Reply Last reply
            0
            • F Fred 34

              How can we write the long source of a program in 2 or 3 files and relate them together at build time.

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              faraz34 wrote:

              How can we write the long source of a program in
              2 or 3 files and relate them together at build time.

              1. Design your application so that you can break the functionality into classes. Classes normally are rather small. This step has nothing to do with actually writing code. 2. Implement each class in a different file. 3. In C# you put all of the classes in a project which is then managed via a solution.

              P 1 Reply Last reply
              0
              • L Lost User

                The question (as with so many) is somewhat open to interpretation. :(

                Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

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

                Yes, but the wording "two or three files" are a give-away. ..with everybody recommending on how to distribute classes over multiple files :D

                Bastard Programmer from Hell :suss:

                L 1 Reply Last reply
                0
                • L Lost User

                  Yes, but the wording "two or three files" are a give-away. ..with everybody recommending on how to distribute classes over multiple files :D

                  Bastard Programmer from Hell :suss:

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

                  Which is why I made the suggestion that I did.

                  Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                  A 1 Reply Last reply
                  0
                  • F Fred 34

                    How can we write the long source of a program in 2 or 3 files and relate them together at build time.

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

                    csc /out:My.exe *.cs

                    Will compile all .cs files within that folder into My.exe. Snippet taken from MSDN[^].

                    Bastard Programmer from Hell :suss:

                    P 1 Reply Last reply
                    0
                    • F Fred 34

                      How can we write the long source of a program in 2 or 3 files and relate them together at build time.

                      B Offline
                      B Offline
                      BobJanova
                      wrote on last edited by
                      #10

                      In addition to using *.cs you can also put the specific files:

                      csc MyFirstClass.cs MySecondClass.cs etc.cs

                      The name of the first will be used to name the output (i.e. MyFirstClass.exe in this case) unless you specify a /out: target. IDEs generally hide this away from you – are you writing code in a text editor? You don't normally need to do that, as there are good free IDEs available for .Net.

                      1 Reply Last reply
                      0
                      • J jschell

                        faraz34 wrote:

                        How can we write the long source of a program in
                        2 or 3 files and relate them together at build time.

                        1. Design your application so that you can break the functionality into classes. Classes normally are rather small. This step has nothing to do with actually writing code. 2. Implement each class in a different file. 3. In C# you put all of the classes in a project which is then managed via a solution.

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

                        jschell wrote:

                        3. In C# you put all of the classes in a project which is then managed via a solution.

                        You mean "in Visual Studio"; C# neither knows nor cares about projects and solutions.

                        1 Reply Last reply
                        0
                        • L Lost User

                          csc /out:My.exe *.cs

                          Will compile all .cs files within that folder into My.exe. Snippet taken from MSDN[^].

                          Bastard Programmer from Hell :suss:

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

                          Yes, but I use /recurse:"*.cs"

                          1 Reply Last reply
                          0
                          • L Lost User

                            Which is why I made the suggestion that I did.

                            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                            A Offline
                            A Offline
                            AmitGajjar
                            wrote on last edited by
                            #13

                            better way is to ask for more information about the question.!!! @faraz34 : what exactly you would like to achieve ? whats your problem ? thanks -Amit.

                            L L 2 Replies Last reply
                            0
                            • A AmitGajjar

                              better way is to ask for more information about the question.!!! @faraz34 : what exactly you would like to achieve ? whats your problem ? thanks -Amit.

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

                              Not at all; I gave an answer which may be the right one. If not then OP can respond with more details.

                              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                              1 Reply Last reply
                              0
                              • A AmitGajjar

                                better way is to ask for more information about the question.!!! @faraz34 : what exactly you would like to achieve ? whats your problem ? thanks -Amit.

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

                                the ways of an MVP, you should treat with the greatest respect! :)

                                Luc Pattyn [My Articles] Nil Volentibus Arduum


                                Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.

                                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