Lecture overview -- Keyboard shortcut: 'u'  Previous page: Commands and Control Structures -- Keyboard shortcut: 'p'  Next page: Input and output -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 15 : 43
Object-oriented Programming in C#
Introduction to C#
Functions

On this page we will look at parameter passing techniques. C only supports call by value. Call by reference in C is in reality call by value passing of pointers. C# offers a variety of different parameter passing modes. We also discuss overloaded functions - functions of the same name distinguished by parameters of different types.

All functions in C# are members of classes or structs

C# supports are variety of different function members: methods, properties, events, indexers, operators, and constructors

  • Similarities

    • The basic ideas of function definition and function call are the same in C and C#

  • Differences

    • Several different parameter passing techniques in C#

      • Call by value. For input. No modifier.

      • Call by reference. For input and output or output only

        • Input and output: Modifier ref

        • Output: Modifier out

        • Modifiers used both with formal and actual parameters

    • Functions with a variable number of input parameters in C# (cleaner than in C)

    • Overloaded function members in C#

    • First class functions (delegates) in C#

/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/functions/fragmented/simple-function-demo.csDemonstration of simple functions in C#. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/functions/fragmented/parameters.csDemonstration of parameter passing in C#.


/user/normark/oop-csharp-1/sources/c-sharp/introductory-examples/functions/fragmented/overloading.csDemonstration of overloaded methods in C#.