CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 4 th Lecture Pavel Ježek

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
Programming Languages and Paradigms
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.
BY BOWYA G.  This International Standard is based on a submission from Hewlett-Packard, Intel, and Microsoft, that describes a language called C#. 
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].
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
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.
Advanced .NET Programming I 13th Lecture
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
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
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.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
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.
Review for Final Exam. Contents 5 questions (20 points each) + 1 bonus question (20 points) – Basic concepts in Chapters 1-4 – Chapters 5-9 – Bonus: Chapter.
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.
Methods Awesomeness!!!. Methods Methods give a name to a section of code Methods give a name to a section of code Methods have a number of important uses.
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.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
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 5 th Lecture Pavel Ježek
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
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
Methods Attributes Method Modifiers ‘static’
Advanced .NET Programming I 4th Lecture
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.
Conditional Statements
Review for Final Exam.
Group Status Project Status.
Reference Parameters.
Review for Final Exam.
CSC 142 Arrays [Reading: chapter 12].
A simple function.
Programming Languages and Paradigms
Advanced .NET Programming I 13th Lecture
Advanced .NET Programming I 5th Lecture
Standard Version of Starting Out with C++, 4th Edition
C# Language & .NET Platform 10th 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:

CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 4 th Lecture Pavel Ježek 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 (

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

Visibility Visibility modifiers: publicAccess is not restricted. protectedAccess is limited to the containing class or types derived from the containing class. internalAccess is limited to the current assembly. protected internalAccess is limited to the current assembly or types derived from the containing class. privateAccess is limited to the containing type. Default visibility in: enumpublic classprivate interfacepublic structprivate

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

Parameters 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 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 -"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 }

Parameters 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 value" -formal parameter is a copy of the actual parameter -actual parameter is an expression -similar to ref parameters but no value is passed by the caller. -must not be used in the method before it got a value. -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); } -"call by reference" -formal parameter is an alias for the actual parameter (address of actual parameter is passed) -actual parameter must be a variable -"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 }

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

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

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