C# Language & .NET Platform 10th Lecture

Slides:



Advertisements
Similar presentations
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
Advertisements

Programming Languages and Paradigms
Programming Languages and Paradigms The C Programming Language.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 6 th Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 2 nd Lecture Pavel Ježek
Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 4 th Lecture Pavel Ježek
1 Lecture 18:User-Definded function II(cont.) Introduction to Computer Science Spring 2006.
1 Chapter 7 User-Defined Methods Java Programming from Thomson Course Tech, adopted by kcluk.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Chapter 7: User-Defined Methods
CSC 142 J 1 CSC 142 Arrays [Reading: chapter 10].
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 7 th & 8 th Lecture Pavel Ježek.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 11 th Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 11 th Lecture Pavel Ježek
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
1 9/6/05CS360 Windows Programming CS360 Windows Programming.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
User Defined Methods Methods are used to divide complicated programs into manageable pieces. There are predefined methods (methods that are already provided.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 6 th Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 8 th Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 11 th Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 9 th Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 2 nd Lecture Pavel Ježek
Introduction to C# By: Abir Ghattas Michel Barakat.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 4 th Lecture Pavel Ježek
- This slide is intentionally left blank - Some of the slides are based on University of Linz.NET presentations. © University of Linz, Institute for System.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 7 th Lecture Pavel Ježek
1 Statements © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming II 3 rd Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming II 2 nd Lecture Pavel Ježek
CS314 – Section 5 Recitation 9
Chapter 7 User-Defined Methods.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 7 User-Defined Methods.
Advanced .NET Programming II 6th Lecture
Advanced .NET Programming II 4th Lecture
Programming Languages and Paradigms
Methods Attributes Method Modifiers ‘static’
Advanced .NET Programming I 4th Lecture
CSE 143 Introduction to C++ [Appendix B] 4/11/98.
Learning Objectives Pointers Pointer in function call
Advanced .NET Programming I 6th Lecture
Programming Paradigms
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
CSC 253 Lecture 8.
CSC 253 Lecture 8.
Review for Final Exam.
Reference Parameters.
Parameter Passing in Java
Review for Final Exam.
CSC 142 Arrays [Reading: chapter 12].
Java Programming Language
A simple function.
Programming Languages and Paradigms
ENERGY 211 / CME 211 Lecture 8 October 8, 2008.
Advanced .NET Programming I 13th Lecture
Advanced .NET Programming I 5th Lecture
Advanced .NET Programming I 7th Lecture
- This slide is intentionally left blank -
Advanced .NET Programming I 4th Lecture
C# Language & .NET Platform 11th Lecture
Advanced .NET Programming I 6th Lecture
Corresponds with Chapter 5
C# Language & .NET Platform 3rd Lecture
C# Language & .NET Platform 9th Lecture
C# Language & .NET Platform 4th Lecture
C# Language & .NET Platform 8th Lecture
C# Language & .NET Platform 12th Lecture
Presentation transcript:

C# Language & .NET Platform 10th Lecture Pavel Ježek pavel.jezek@d3s.mff.cuni.cz Some of the slides are based on University of Linz .NET presentations. © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License (http://www.msdnaa.net/curriculum/license_curriculum.aspx)

CLI Type System All types Value types Reference types Pointers (allocated in-place [with exceptions]) Reference types (allocated on managed heap) Pointers Structures Enumerations Classes (e.g. strings) Interfaces Arrays Delegates Simple types (Int32, Int64, Double, Boolean, Char, …) Nullables User defined structures

Parameters - "call by value" value parameters (input parameters) void Inc(int x) {x = x + 1;} void f() { int val = 3; Inc(val); // val == 3 } - "call by value" - formal parameter is a copy of the actual parameter - actual parameter is an expression

Parameters - "call by value" value parameters (input parameters) void Inc(int x) {x = x + 1;} void f() { int val = 3; Inc(val); // val == 3 } - "call by value" - formal parameter is a copy of the actual parameter - actual parameter is an expression - "call by reference" - formal parameter is an alias for the actual parameter (address of actual parameter is passed) - actual parameter must be a variable ref parameters (transient parameters) void Inc(ref int x) { x = x + 1; } void f() { int val = 3; Inc(ref val); // val == 4 }

Declaration of Local Variables void foo(int a) { int b; if (...) { int b; // error: b is already declared in the outer block int c; int d; ... } else { int a; // error: a is already declared in the outer block (parameter) int d; // ok: no conflict with d in the if block } for (int i = 0; ...) {...} for (int i = 0; ...) {...} // ok: no conflict with i from the previous loop int c; // error: c is already declared in a nested block int e = 1, f; if (e == 1) { f = 2; e = f; // error: f is not initialized in every possible execution path

Parameters - "call by value" - formal parameter is a copy of the actual parameter - actual parameter is an expression value parameters (input parameters) void Inc(int x) {x = x + 1;} void f() { int val = 3; Inc(val); // val == 3 } - "call by reference" - formal parameter is an alias for the actual parameter (address of actual parameter is passed) - actual parameter must be a variable ref parameters (transient parameters) void Inc(ref int x) { x = x + 1; } void f() { int val = 3; Inc(ref val); // val == 4 } - similar to ref parameters but no value is passed by the caller. - must not be used in the method before it got a value. out parameters (output parameters) void Read (out int first, out int next) { first = Console.Read(); next = Console.Read(); } void f() { int first, next; Read(out first, out next);