Teaching%20Session%203

Teaching%20Session%203 - Engineering 1D04 Teaching Session...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering 1D04 Teaching Session 3 Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 1 void doIt() { textBox1.Text = "Hello Hamilton!!"; } Introduction to Methods In Lab 2 you were introduced to creating simple methods. Lets recap Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 2 ClickMe Button handler doIt() MouseOverMe Button handler Text in Textbox ClickMe Button Pushed MouseOverMe Button Entered void doIt() { textBox1.Text = "Hello Hamilton!!"; } Introduction to Methods Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 3 doIt has no inputs (no parameters) and no outputs (a void return type). void doIt() Method Signature Return Type Parameters Introduction to Methods Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 2 ClickMe Button handler doIt() MouseOverMe Button handler Text in Textbox ClickMe Button Pushed MouseOverMe Button Entered void doIt() { textBox1.Text = "Hello Hamilton!!"; } Introduction to Methods Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 3 doIt has no inputs (no parameters) and no outputs (a void return type). void doIt() Method Signature Return Type Parameters Introduction to Methods Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 4 To make doIt() more useful we can add a parameter (an input). void doIt2(string string4Textbox) { textBox1.Text = string4Textbox; } Introduction to Methods Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 5 doIt2("Hello Hamilton!!"); Introduction to Methods When doIt2 is called, we now need to pass it a parameter. Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 6 doIt2("Hello Hamilton!!"); void doIt2(string string4Textbox) { textBox1.Text = string4Textbox; } "Hello Hamilton!!" Introduction to Methods A copy of the string "Hello Hamilton!!" is then stored within the variable string4Textbox. Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 7 doIt2 could also be called with a string variable as a parameter. string myStringVariable = "Hello"; doIt2(myStringVariable); void doIt2(string string4Textbox) { textBox1.Text = string4Textbox; } "Hello" Introduction to Methods Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 8 A copy of the variable's data is passed as a parameter. The copy is then no longer associated with myStringVariable. string myStringVariable = "Hello"; doIt2(myStringVariable); void doIt2(string string4Textbox) { textBox1.Text = string4Textbox; } "Hello" Introduction to Methods Copyright 2006 David Das, Ryan Lortie, Alan Wassyng 9 string sum(int x1, int x2) { return Convert.ToString(x1 + x2); } Method Parameters Lets create a method to add two numbers together and return a string containing the result....
View Full Document

This note was uploaded on 12/05/2010 for the course ENG 1D04 taught by Professor Done during the Spring '08 term at McMaster University.

Page1 / 27

Teaching%20Session%203 - Engineering 1D04 Teaching Session...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online