120 likes | 181 Views
Methods in Programming. Jonathan Heimdal November 8, 2012 2A Computer Technology. Main Method. User Method. Main bodies of code go here Starts with capital letters Main can access user methods easily. Can be referred to several times in main Usually starts with lower case letters
E N D
Methods in Programming Jonathan Heimdal November 8, 2012 2A Computer Technology
Main Method User Method • Main bodies of code go here • Starts with capital letters • Main can access user methods easily • Can be referred to several times in main • Usually starts with lower case letters • Used to shorten and simplify programs Method Comparison
Method name isMain Main method has parameters inside parenthesis Main code goes inside opening and closing curly braces {CODE HERE} Main Method
Method name is OpenReadWriteFileAsync User method has parameters inside parenthesis User Method
Purposes for User Methods • Used to shorten and simplify programs • Saves time when writing large programs • Makes programs easier to read “A purpose for a user built method, is if, for example, you must use the same block of code several times in a program, you don’t have to retype the same block of code over and over. All you have to do is type the name of the method and the parameters in place of the block of code.” (Heimdal, 2012)
All methods are outside of main • Methods are sometimes in separate class • Class variables can indicate methods How to Identify
Constructors • Getters • Setters • Methods Types of “Methods”
Identified by having the same name as class name • Can do similar actions methods can Constructors
“Getters are types of methods that are similar to a read only pdf text file. It only allows the user to read what is displayed, and does not allow user to edit.” (Heimdal, 2012) • Gives only get access to user Getters
“Setters are similar to getters except for that you may read and edit. Setters allow user to access and edit or use the code in the setter method.” (Heimdal, 2012) • Gives only set access to user Setters
“Methods cannot be inside of other methods. However, a method can also rely on other methods. For example, in a method, you could have a block of code that instigates another action. This action is done by another method. So, a method can rely on other methods inside its’ own code to achieve the overall program.” (Heimdal, 2012) Methods inside of Methods?
Heimdal, J. (2012, November 18). Purposes for Methods. (M. Tamietti, Interviewer) • Navneeth. (2012, July 22). Compiling Multiple main() methods in C#. Retrieved November 18, 2012, from www.wordpress.com: http://crmerp4bus.wordpress.com/2012/07/22/compiling-multiple-main-methods-in-c/ • Sabnis, M. (2012, April 6). Asynchronous Programming using C# 4.5 and Visual Studio 2011. Retrieved November 18, 2012, from www.dotnetcurry.com: www.dotnetcurry.com/ShowArticle.aspx?ID=797 Bibliography