Overloading Members in C#: Understanding Signatures and Rules, Slides of C Sharp Programming

Overloading members in c# programming, including how multiple procedures with the same name are possible, using overloaded members with examples of tostring() method and streamwriter constructor, rules for overloading members such as unique signatures and argument counts, and how .net calls an overloaded member with examples of uml class diagrams and type conversion.

Typology: Slides

2012/2013

Uploaded on 09/27/2013

vikrant
vikrant 🇮🇳

4.4

(9)

119 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming Pillars
Overloading
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Overloading Members in C#: Understanding Signatures and Rules and more Slides C Sharp Programming in PDF only on Docsity!

Programming Pillars

Overloading

Overloading Members

(Introduction)

 Overloading provides the means by which

multiple procedures share the same name

 An overloaded procedure or constructor is

generically referred to as an overloaded

member

Using Overloaded Members

(Example 1)

 The ToString() method of numeric data types is overloaded  One method accepts no arguments and converts the value to a string  A second method accepts one argument – a format string  Examples:

lblToString1.Text = _ System.Int32.MaxValue.ToString() lblToString2.Text = _ System.Int32.MaxValue.ToString("C")

Using Overloaded Members

(Example 2)

 The StreamWriter constructor is overloaded  Note the two different argument lists  If the file exists, it will be overwritten CurrentWriter = new _ StreamWriter(ofdCurrent.FileName)

 Use the second argument to append to a file CurrentWriter = new StreamWriter(ofdCurrent.FileName, True)

Rules for Overloading Members

 By creating multiple members having the same name, those members will be considered overloaded  Constructors can be overloaded  Return data type for overloaded methods must be the same

Overloading Members (Example)

 The declaration for three overloaded members (see IS389OverloadingCSharp.zip for code)

How .NET Calls an

Overloaded Member

 Remember the calling procedure has

arguments

 .NET calls an overloaded procedure based on

the argument count and types

 Widening type coercion is used to match

arguments

 A syntax error will occur if a match cannot be

found

UML Class diagrams

(Overloading)

 Each overloaded member has an entry in the

UML class diagram

 Specify members, parameters, and return data

types as before

 Visio requires that the signature vary for each

overloaded member