C# Language & .NET Platform 8th 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

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
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 4 th Lecture Pavel Ježek
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Lecture 9 Concepts of Programming Languages
.Net vs. Java And why.Net is better. Hello World in Java.
Abstract Data Types and Encapsulation Concepts
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
Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C#.NET.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
ILM Proprietary and Confidential -
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
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
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.
Lecture Set 1 Part B: Understanding Visual Studio and.NET – Structure and Terminology 1/16/ :04 PM.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 7 th Lecture Pavel Ježek
1 Lecture 05 Project: C#, ASP,.NET Friday, January 13, 2006.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming II 5 th Lecture Pavel Ježek
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
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 I 7 th Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming II 2 nd Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 2 nd Lecture Pavel Ježek
Chapter 5: Enhancing Classes
Advanced .NET Programming I 2nd Lecture
Classes (Part 1) Lecture 3
Inheritance ITI1121 Nour El Kadri.
2.7 Inheritance Types of inheritance
Advanced .NET Programming II 6th Lecture
Advanced .NET Programming II 10th Lecture
Advanced .NET Programming I 8th Lecture
Advanced .NET Programming I 4th Lecture
Advanced .NET Programming I 7th Lecture
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Advanced .NET Programming I 6th Lecture
Creating Your OwnClasses
Creating and Using Classes
Lecture 9 Concepts of Programming Languages
Review for Midterm Exam
Functions, Return Values, Parameters Getters and Setters
Review for Midterm Exam
Fundaments of Game Design
Advanced .NET Programming I 13th Lecture
Advanced .NET Programming I 8th Lecture
Advanced .NET Programming I 5th Lecture
C# Language & .NET Platform 10th Lecture
Advanced .NET Programming I 7th Lecture
- This slide is intentionally left blank -
Advanced .NET Programming I 3rd Lecture
Advanced .NET Programming I 4th Lecture
C# Language & .NET Platform 11th Lecture
Advanced .NET Programming I 6th Lecture
C# Language & .NET Platform 3rd Lecture
C# Language & .NET Platform 9th Lecture
C# Language & .NET Platform 4th Lecture
C# Language & .NET Platform 12th Lecture
Chengyu Sun California State University, Los Angeles
Lecture 9 Concepts of Programming Languages
5. OOP OOP © 2003 Microsoft.
Presentation transcript:

C# Language & .NET Platform 8th 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)

Indexers (parametric properties) Programmable operator for indexing a collection class File { FileStream s; public int this [int index] { get { s.Seek(index, SeekOrigin.Begin); return s.ReadByte(); } set { s.Seek(index, SeekOrigin.Begin); s.WriteByte((byte) value); Usage File f = ...; int x = f[10]; // calls f.get(10) f[10] = 'A'; // calls f.set(10, 'A') get or set method can be omitted (write-only / read-only) indexers can be overloaded with different index type .NET library has indexers for string (s[i]), List (a[i]), etc.

Indexers (other example 1) class MonthlySales { int[] apples = new int[12]; int[] bananas = new int[12]; ... public int this[int month] { // set method omitted => read-only get { return apples[month-1] + bananas[month-1]; } } public int this[string month] { // overloaded read-only indexer get { switch (month) { case "Jan": return apples[0] + bananas[0]; case "Feb": return apples[1] + bananas[1]; MonthlySales sales = new MonthlySales(); Console.WriteLine(sales[1] + sales["Feb"]);

Indexers (other example 2) class MonthlySales { int[] apples = new int[12]; int[] bananas = new int[12]; ... public int this[int month] { // set method omitted => read-only get { return apples[month-1] + bananas[month-1]; } } public int this[int month, string kind] { // overloaded read-only indexer get { switch (kind) { case "apple": return apples[month-1]; case "banana": return bananas[month-1]; MonthlySales sales = new MonthlySales(); Console.WriteLine(sales[1]); Console.WriteLine(sales[1, "banana"]); Console.WriteLine(sales[1, "apple"]);

Special Operator Methods Operators, indexers, properties and events are compiled into “normal” methods - get_* (property getter) - set_* (property setter) - get_Item (indexer getter) - set_Item (indexer setter) etc.

Visibility class private Visibility modifiers: public Access is not restricted. protected Access is limited to the containing class or types derived from the containing class. internal Access is limited to the current assembly. protected internal Access is limited to the current assembly or types derived from the containing class. private Access is limited to the containing type. class private interface public