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. C# Newbie: What is the ":" for?? [modified]

C# Newbie: What is the ":" for?? [modified]

Scheduled Pinned Locked Moved C#
questioncsharpperformancetutorialcareer
7 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.
  • G Offline
    G Offline
    Goalie35
    wrote on last edited by
    #1

    Hey guys. I just started a new job which requires C# skills so I'm trying to get myself up to speed and while I've been able to understand most of the stuff so far, one thing I don't understand is what is the purpose of the ":" and everything after it when creating a class? For example, what does the ":" mean in the following line and what is the purpose for "ExcelReport, IReport": ------------------------------------------------ public class SampleClass: ExcelReport, IReport ------------------------------------------------- This code is basically from one of their applications. It writes a report to an excel file. Oh, also if it's not too much trouble, can anyone explain what ":base()" is used for? For example: --------------------------------------- public SampleClass(FileInfo fileName) : base(fileName) --------------------------------------- Thanks again guys. -Goalie35 -- modified at 9:02 Thursday 10th August, 2006

    V R E L 4 Replies Last reply
    0
    • G Goalie35

      Hey guys. I just started a new job which requires C# skills so I'm trying to get myself up to speed and while I've been able to understand most of the stuff so far, one thing I don't understand is what is the purpose of the ":" and everything after it when creating a class? For example, what does the ":" mean in the following line and what is the purpose for "ExcelReport, IReport": ------------------------------------------------ public class SampleClass: ExcelReport, IReport ------------------------------------------------- This code is basically from one of their applications. It writes a report to an excel file. Oh, also if it's not too much trouble, can anyone explain what ":base()" is used for? For example: --------------------------------------- public SampleClass(FileInfo fileName) : base(fileName) --------------------------------------- Thanks again guys. -Goalie35 -- modified at 9:02 Thursday 10th August, 2006

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      inheritance SampleClass is inherited from ExcelReport. :Base(fileName) calls the constructor of the base class. Hope this helps.

      I've found a living worth working for, but I haven't found work worth living for. :beer:
      :jig:

      1 Reply Last reply
      0
      • G Goalie35

        Hey guys. I just started a new job which requires C# skills so I'm trying to get myself up to speed and while I've been able to understand most of the stuff so far, one thing I don't understand is what is the purpose of the ":" and everything after it when creating a class? For example, what does the ":" mean in the following line and what is the purpose for "ExcelReport, IReport": ------------------------------------------------ public class SampleClass: ExcelReport, IReport ------------------------------------------------- This code is basically from one of their applications. It writes a report to an excel file. Oh, also if it's not too much trouble, can anyone explain what ":base()" is used for? For example: --------------------------------------- public SampleClass(FileInfo fileName) : base(fileName) --------------------------------------- Thanks again guys. -Goalie35 -- modified at 9:02 Thursday 10th August, 2006

        R Offline
        R Offline
        Roy Heil
        wrote on last edited by
        #3

        The : in the class declaration indicates that your class will inherite from some other class. In the example you gave: public class SampleClass: ExcelReport, IReport SampleClass inherits from the class ExcelReport, and the interface IReport.

        Roy.

        1 Reply Last reply
        0
        • G Goalie35

          Hey guys. I just started a new job which requires C# skills so I'm trying to get myself up to speed and while I've been able to understand most of the stuff so far, one thing I don't understand is what is the purpose of the ":" and everything after it when creating a class? For example, what does the ":" mean in the following line and what is the purpose for "ExcelReport, IReport": ------------------------------------------------ public class SampleClass: ExcelReport, IReport ------------------------------------------------- This code is basically from one of their applications. It writes a report to an excel file. Oh, also if it's not too much trouble, can anyone explain what ":base()" is used for? For example: --------------------------------------- public SampleClass(FileInfo fileName) : base(fileName) --------------------------------------- Thanks again guys. -Goalie35 -- modified at 9:02 Thursday 10th August, 2006

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #4

          Other have provided the correct answer but I must recommend purchasing a book on C# if you are at this level of newness. Many of these sort of questions will be covered ad naseum in the first few chapters catapulting you ahead of your peers (assuming you asked them and they didn't know either) Not only will you have the what but you will have the why.

          A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

          1 Reply Last reply
          0
          • G Goalie35

            Hey guys. I just started a new job which requires C# skills so I'm trying to get myself up to speed and while I've been able to understand most of the stuff so far, one thing I don't understand is what is the purpose of the ":" and everything after it when creating a class? For example, what does the ":" mean in the following line and what is the purpose for "ExcelReport, IReport": ------------------------------------------------ public class SampleClass: ExcelReport, IReport ------------------------------------------------- This code is basically from one of their applications. It writes a report to an excel file. Oh, also if it's not too much trouble, can anyone explain what ":base()" is used for? For example: --------------------------------------- public SampleClass(FileInfo fileName) : base(fileName) --------------------------------------- Thanks again guys. -Goalie35 -- modified at 9:02 Thursday 10th August, 2006

            L Offline
            L Offline
            LongRange Shooter
            wrote on last edited by
            #5

            I would agree with Ennis on getting yourself a book. I would suggest that you may want to splurge on two books: Get a small book to get a quick overview of C#. Then a detailed one that goes into everything there is to know. Once you feel comfortable, get yourself the Design Patterns in C# book as this will become your development bible. When you do inheritance you can inherit an interface ( public interface ISomething) and you can inherit an abstract class or inheritable class ( public abstract class Something or public class Something). You can only inherit a single object and that must be the first name in your list after ':'. All others must be interfaces. This is called single inheritance. The benefits of inheritance is that you automatically gain the methods the original class already had written and tested. (which means you may not have to) If you want to change or add behavior you then override a method and add your own code. Calling base.Method() either in the method signature or in your method is how you execute the code your program is hiding from users of your program. So if you see something like this:

            public override bool MyOveridableMethod(string parm, bool state)
            :base(parm,state)
            {
            }

            then the developer wants the base method to execute first before executing his own code. If you see code like this:

            public override bool MyOveridableMethod(string parm, bool state)
            {
            ....
            }

            then the developer wants to control when (or if) the underlying code is executed. If this description totally loses you, then it is further proof you really need to do some reading. But you will absorb it and in a few months it will all start to sound like common English. -- modified at 16:33 Thursday 10th August, 2006

            E 1 Reply Last reply
            0
            • L LongRange Shooter

              I would agree with Ennis on getting yourself a book. I would suggest that you may want to splurge on two books: Get a small book to get a quick overview of C#. Then a detailed one that goes into everything there is to know. Once you feel comfortable, get yourself the Design Patterns in C# book as this will become your development bible. When you do inheritance you can inherit an interface ( public interface ISomething) and you can inherit an abstract class or inheritable class ( public abstract class Something or public class Something). You can only inherit a single object and that must be the first name in your list after ':'. All others must be interfaces. This is called single inheritance. The benefits of inheritance is that you automatically gain the methods the original class already had written and tested. (which means you may not have to) If you want to change or add behavior you then override a method and add your own code. Calling base.Method() either in the method signature or in your method is how you execute the code your program is hiding from users of your program. So if you see something like this:

              public override bool MyOveridableMethod(string parm, bool state)
              :base(parm,state)
              {
              }

              then the developer wants the base method to execute first before executing his own code. If you see code like this:

              public override bool MyOveridableMethod(string parm, bool state)
              {
              ....
              }

              then the developer wants to control when (or if) the underlying code is executed. If this description totally loses you, then it is further proof you really need to do some reading. But you will absorb it and in a few months it will all start to sound like common English. -- modified at 16:33 Thursday 10th August, 2006

              E Offline
              E Offline
              Ennis Ray Lynch Jr
              wrote on last edited by
              #6

              Im going to have to ask for both n's in Ennis for obvious reasons. The two are pronounced entirely different and misspelling lead to humourous consequences.

              A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

              L 1 Reply Last reply
              0
              • E Ennis Ray Lynch Jr

                Im going to have to ask for both n's in Ennis for obvious reasons. The two are pronounced entirely different and misspelling lead to humourous consequences.

                A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

                L Offline
                L Offline
                LongRange Shooter
                wrote on last edited by
                #7

                So sorry. It is modified so no one will read it with a long E. :laugh:

                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