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. Class Design Question.

Class Design Question.

Scheduled Pinned Locked Moved C#
questiondesign
4 Posts 4 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.
  • J Offline
    J Offline
    jchigg2000
    wrote on last edited by
    #1

    Hello all. I am trying to decide if it's better to have all my classes in one .cs file within my project(for instance 'MyClasses') and then just put all my classes inside that file. This would result in code like this. MyClasses.MyClass x = new MyClasses.MyClass(): The alternative is obviously putting each individual class in it's own .cs file under the project. This would enable me to simply do MyClass x = new MyClass(); What is the advantage/disadvantage of doing this both ways? I do not want to build the classes in a separate project and import the dll. So I'm really just wondering about these 2 different ways of building the classes in my project.

    J P J 3 Replies Last reply
    0
    • J jchigg2000

      Hello all. I am trying to decide if it's better to have all my classes in one .cs file within my project(for instance 'MyClasses') and then just put all my classes inside that file. This would result in code like this. MyClasses.MyClass x = new MyClasses.MyClass(): The alternative is obviously putting each individual class in it's own .cs file under the project. This would enable me to simply do MyClass x = new MyClass(); What is the advantage/disadvantage of doing this both ways? I do not want to build the classes in a separate project and import the dll. So I'm really just wondering about these 2 different ways of building the classes in my project.

      J Offline
      J Offline
      J a a n s
      wrote on last edited by
      #2

      IMHO the later is better as it is easy to manage. But don't forget to use namespace[^].;P

      *jaans

      1 Reply Last reply
      0
      • J jchigg2000

        Hello all. I am trying to decide if it's better to have all my classes in one .cs file within my project(for instance 'MyClasses') and then just put all my classes inside that file. This would result in code like this. MyClasses.MyClass x = new MyClasses.MyClass(): The alternative is obviously putting each individual class in it's own .cs file under the project. This would enable me to simply do MyClass x = new MyClass(); What is the advantage/disadvantage of doing this both ways? I do not want to build the classes in a separate project and import the dll. So I'm really just wondering about these 2 different ways of building the classes in my project.

        P Offline
        P Offline
        phannon86
        wrote on last edited by
        #3

        Agreed, the latter is better. No need to have a class filled with classes purely for the purposes of grouping. Just make sure they're all under the same namespace.

        He who makes a beast out of himself gets rid of the pain of being a man

        1 Reply Last reply
        0
        • J jchigg2000

          Hello all. I am trying to decide if it's better to have all my classes in one .cs file within my project(for instance 'MyClasses') and then just put all my classes inside that file. This would result in code like this. MyClasses.MyClass x = new MyClasses.MyClass(): The alternative is obviously putting each individual class in it's own .cs file under the project. This would enable me to simply do MyClass x = new MyClass(); What is the advantage/disadvantage of doing this both ways? I do not want to build the classes in a separate project and import the dll. So I'm really just wondering about these 2 different ways of building the classes in my project.

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          you are confusing physical .cs files with namespaces! It is 100% preferable to stick to the one-class-per-file method.

          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