Methods in Programming
description
Transcript of Methods in Programming
Methods in Programming
Jonathan HeimdalNovember 8, 2012
2A Computer Technology
Method Comparison
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
Main Method
• Method name is Main
• Main method has parameters inside parenthesis
• Main code goes inside opening and closing curly braces {CODE HERE}
User Method
• Method name is OpenReadWriteFileAsync
• User method has parameters inside parenthesis
Purposes for User Methods“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)
Used to shorten and simplify programs
Saves time when writing large programs
Makes programs easier to read
How to Identify
All methods are outside of main
Methods are sometimes in separate class
Class variables can indicate methods
Types of “Methods”
Constructors
Getters
Setters
Methods
Constructors
Identified by having the same name as class name
Can do similar actions methods can
Getters
“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
Setters
“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
Methods inside of Methods?
“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)
Bibliography
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