|
|
Contents
Overview 1
Using Methods 2
Using Parameters 16
Using Overloaded Methods 30
Lab 5: Creating and Using Methods 38
Review 50
Module 5: Methods and
Parameters
This course is based on the prerelease Beta 1 version of Microsoft? Visual Studio .NET.
Content in the final release of the course may be different from the content included in
this prerelease version. All labs in the course are to be completed with the Beta 1
version of Visual Studio .NET.
Information in this document is subject to change without notice. The names of companies,
products, people, characters, and/or data mentioned herein are fictitious and are in no way intended
to represent any real individual, company, product, or event, unless otherwise noted. Complying
with all applicable copyright laws is the responsibility of the user. No part of this document may
be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Microsoft Corporation. If, however, your only
means of access is electronic, permission to print one copy is hereby granted.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.
ó 2001 Microsoft Corporation. All rights reserved.
Microsoft, ActiveX, BizTalk, IntelliSense, JScript, Microsoft Press, MSDN, PowerPoint, Visual
Basic, Visual C++, Visual C#, Visual Studio, Windows, Windows NT, and Windows Media are
either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other
countries.
Other product and company names mentioned herein may be the trademarks of their respective
owners.
Module 5: Methods and Parameters 1
Overview
n Using Methods
n Using Parameters
n Using Overloaded Methods
In designing most applications, you divide the application into functional units.
This is a central principle of application design because small sections of code
are easier to understand, design, develop, and debug. Dividing the application
into functional units also allows you to reuse functional components throughout
the application.
In C#, you structure your application into classes that contain named blocks of
code; these are called methods. A method is a member of a class that performs
an action or computes a value.
After completing this module, you will be able to:
n Create static methods that accept parameters and return values.
n Pass parameters to methods in different ways.
n Declare and use overloaded methods.
2 Module 5: Methods and Parameters
u Using Methods
n Defining Methods
n Calling Methods
n Using the return Statement
n Using Local Variables
n Returning Values
In this section, you will learn how to use methods in C#. Methods are important
mechanisms for struc turing program code. You will learn how to create
methods and how to call them from within a single class and from one class to
another.
You will learn how to use local variables, as well as how to allocate and
destroy them.
You will also learn how to return a value from a method, and how to use
parameters to transfer data into and out of a method. |
|