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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. General newbie type question

General newbie type question

Scheduled Pinned Locked Moved C#
questioncsharppythonlounge
6 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.
  • S Offline
    S Offline
    shwaguy
    wrote on last edited by
    #1

    Since I lack a mentor I have to ask these basic structure question here. Good guidance is really appreciated. Please be advised that I am thinking of both Python and C# structure; but generalities are good too: Classes: What should go into a class and what should stay out? -I am converting a program to have an OOP structure the program prints out processed results to a file line by line. Should my class for this return the processing results to the main program and then use a function or another class to print the results? -Is it acceptable to have a class return some result but then call on the same class object to process the next logical step of the process? This seems right to me since built in functions seem to do this. eg: Have MyClass read the first line in a file, return it Have the main print the line Have the main call MyClass again but have it read the next line in the object Should I just forget about "functions" and "sub-routines" and throw everything into classes? TIA, The shwa guy

    S P S 3 Replies Last reply
    0
    • S shwaguy

      Since I lack a mentor I have to ask these basic structure question here. Good guidance is really appreciated. Please be advised that I am thinking of both Python and C# structure; but generalities are good too: Classes: What should go into a class and what should stay out? -I am converting a program to have an OOP structure the program prints out processed results to a file line by line. Should my class for this return the processing results to the main program and then use a function or another class to print the results? -Is it acceptable to have a class return some result but then call on the same class object to process the next logical step of the process? This seems right to me since built in functions seem to do this. eg: Have MyClass read the first line in a file, return it Have the main print the line Have the main call MyClass again but have it read the next line in the object Should I just forget about "functions" and "sub-routines" and throw everything into classes? TIA, The shwa guy

      S Offline
      S Offline
      Spacix One
      wrote on last edited by
      #2

      shwaguy wrote:

      Classes: What should go into a class and what should stay out?

      Everything in C# MUST be in a class.

      shwaguy wrote:

      Should my class for this return the processing results

      and

      shwaguy wrote:

      Is it acceptable to have a class return some result but then call on the same class

      Classes in C# can not return values, methods (functions) and properties (think externally accessible variable) can.

      shwaguy wrote:

      Should I just forget about "functions" and "sub-routines" and throw everything into classes?

      your functions have to be contained in a class For an example all of these sources do the same thing

      namespace myApp
      {
      class mainclass
      {
      static void Main(string[] args)
      {
      My_Function_();
      }
      public static void My_function_()
      {
      Console.WriteLine("My \"Function\" was called");
      }
      }
      }

      namespace myApp
      {
      class mainclass
      {
      static void Main(string[] args)
      {
      myclass.My_Function_();
      }
      }
      class myclass
      {
      public static void My_function_()
      {
      Console.WriteLine("My \"Function\" was called");
      }
      }
      }

      namespace myApp
      {
      class mainclass
      {
      static void Main(string[] args)
      {
      anothernamespace.myclass.My_Function_();
      }
      }
      }
      namespace anothernamespace
      {
      class myclass
      {
      public static void My_function_()
      {
      Console.WriteLine("My \"Function\" was called");
      }
      }
      }


      -Spacix All your skynet questions[^] belong to solved

      M 1 Reply Last reply
      0
      • S Spacix One

        shwaguy wrote:

        Classes: What should go into a class and what should stay out?

        Everything in C# MUST be in a class.

        shwaguy wrote:

        Should my class for this return the processing results

        and

        shwaguy wrote:

        Is it acceptable to have a class return some result but then call on the same class

        Classes in C# can not return values, methods (functions) and properties (think externally accessible variable) can.

        shwaguy wrote:

        Should I just forget about "functions" and "sub-routines" and throw everything into classes?

        your functions have to be contained in a class For an example all of these sources do the same thing

        namespace myApp
        {
        class mainclass
        {
        static void Main(string[] args)
        {
        My_Function_();
        }
        public static void My_function_()
        {
        Console.WriteLine("My \"Function\" was called");
        }
        }
        }

        namespace myApp
        {
        class mainclass
        {
        static void Main(string[] args)
        {
        myclass.My_Function_();
        }
        }
        class myclass
        {
        public static void My_function_()
        {
        Console.WriteLine("My \"Function\" was called");
        }
        }
        }

        namespace myApp
        {
        class mainclass
        {
        static void Main(string[] args)
        {
        anothernamespace.myclass.My_Function_();
        }
        }
        }
        namespace anothernamespace
        {
        class myclass
        {
        public static void My_function_()
        {
        Console.WriteLine("My \"Function\" was called");
        }
        }
        }


        -Spacix All your skynet questions[^] belong to solved

        M Offline
        M Offline
        martin_hughes
        wrote on last edited by
        #3

        SpacixOne wrote:

        Everything in C# MUST be in a class.

        What about Structures?

        "It was the day before today.... I remember it like it was yesterday." -Moleman

        S 1 Reply Last reply
        0
        • M martin_hughes

          SpacixOne wrote:

          Everything in C# MUST be in a class.

          What about Structures?

          "It was the day before today.... I remember it like it was yesterday." -Moleman

          S Offline
          S Offline
          Spacix One
          wrote on last edited by
          #4

          Well, there wasn't a question about a struct... but A structure can't inherit from a class (and vice versa) and a struct is created then dies when reaching the closing brace. It is a different animal but no it doesn't have to be defined within a class, but if you use it (write or read a member) that HAS to be inside a class... More C# syntax can be found here http://msdn2.microsoft.com/en-us/library/618ayhy6(vs.80).aspx[^]


          -Spacix All your skynet questions[^] belong to solved

          1 Reply Last reply
          0
          • S shwaguy

            Since I lack a mentor I have to ask these basic structure question here. Good guidance is really appreciated. Please be advised that I am thinking of both Python and C# structure; but generalities are good too: Classes: What should go into a class and what should stay out? -I am converting a program to have an OOP structure the program prints out processed results to a file line by line. Should my class for this return the processing results to the main program and then use a function or another class to print the results? -Is it acceptable to have a class return some result but then call on the same class object to process the next logical step of the process? This seems right to me since built in functions seem to do this. eg: Have MyClass read the first line in a file, return it Have the main print the line Have the main call MyClass again but have it read the next line in the object Should I just forget about "functions" and "sub-routines" and throw everything into classes? TIA, The shwa guy

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

            shwaguy wrote:

            What should go into a class and what should stay out?

            In: Students who have an aptitude for the subject and really want to learn. Out: Students who think the subject is an "easy A" and that "anyone can do it".

            1 Reply Last reply
            0
            • S shwaguy

              Since I lack a mentor I have to ask these basic structure question here. Good guidance is really appreciated. Please be advised that I am thinking of both Python and C# structure; but generalities are good too: Classes: What should go into a class and what should stay out? -I am converting a program to have an OOP structure the program prints out processed results to a file line by line. Should my class for this return the processing results to the main program and then use a function or another class to print the results? -Is it acceptable to have a class return some result but then call on the same class object to process the next logical step of the process? This seems right to me since built in functions seem to do this. eg: Have MyClass read the first line in a file, return it Have the main print the line Have the main call MyClass again but have it read the next line in the object Should I just forget about "functions" and "sub-routines" and throw everything into classes? TIA, The shwa guy

              S Offline
              S Offline
              shwaguy
              wrote on last edited by
              #6

              OK, So the message I seem to be getting is that, anything can be done from anywhere as long as it works. So if it seems write to have MyClass.Function0 return a value and dump that value to a file it is technically OK. Aside from logical organization is there anything style wise I should know? For instance it would not seem right to have MyClass.Function both return a value and print those same values; I seems right to have a seperate class.function take the return values from MyClass.Function and do the writing. That would allow me to have multiple funcitons access my file writing function and eliminate repeat code. Is that right? The shwa guy

              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