C# Newbie: What is the ":" for?? [modified]
-
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
-
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
-
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
-
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
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
-
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
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
orpublic 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
-
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
orpublic 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
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
-
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
So sorry. It is modified so no one will read it with a long E. :laugh: