(H9.1) CirkelKlikker ARRAY int x, y; [ ] int n=0;

Slides:



Advertisements
Similar presentations
EXAMPLE: X Y Z T 5 VERTICES 6 EDGES S Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet.
Advertisements

1 Visual C# "Whidbey": Language Enhancements Anders Hejlsberg Distinguished Engineer Microsoft Corporation Anders Hejlsberg Distinguished.
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Console applicatie static void Main ( ) class Hallo { } { } Console. WriteLine("Hallo " + naam + "!" ); statische methodestatische methoden Console. WriteLine("Wat.
Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag Dallas one-wire interface Opgave:
Fun with Lists for the Novice and Expert Scott Reed Brain Hz Software (760)
Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag functie definitions;.h files;
Data Structures and Collections
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
1 Generic Collections Chapter Objectives You will be able to Use generic collection classes available in the.NET framework.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 14 th Lecture Pavel Ježek
Collections. 2 Objectives Explore collections in System.Collections namespace –memory management –containment testing –sorting –traversal.
Hoofdstuk 13 Object-georiënteerd ontwerp. Methode-aanroep: Type van parameters void paint(Graphics g) { g.drawRect( ); class Graphics { void drawRect(int.
Array nDeclaratie nCreatie nOpvragen nWijzigen nLengte String [ ] a; a = new String[10]; ……a[5]…… a[5] = ……; …a.length… …is eigenlijk overbodig! ArrayList.
Wordpress Hoe doe je dat bij DSE Bloggen met. Log in op de homepage, klik in mijn account op Wordpress installeren.
Iterator Pattern Dr. Neal CIS 480. Iterator An iterator pattern can be used when one class is a collection of things and would like to provide a standardized.
Collection types Collection types.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
Data Binding to Controls Programming in C# Data Binding to Controls CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Copyright © 2006 Thomas P. Skinner1 Chapter 5 Indexers, Interfaces, and Enumerators.
CM0551 Exam Prep. What are an algorithm’s time and space complexity? (2 marks) Answer: The growth rate of the algorithm’s time requirement and the computer.
Dr Dat Tran - Week 4 Lecture Notes 1 ToolStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
Generics Collections. Why do we need Generics? Another method of software re-use. When we implement an algorithm, we want to re-use it for different types.
.NET 2.0 and Visual Studio 2005 SigWin Outline Language enhancements in C# Language enhancements in C# –Generics –Partial types –Anonymous methods.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Data structures for concurrency 1. Ordinary collections are not thread safe Namespaces System.Collections System.Collections.Generics Classes List, LinkedList,
WxHaskell Daan Leijen. Ok…. Dat lijkt me een goed plan. Denk je dat je zo iets dinsdag af kunt hebben en presenteren? Doaitse On donderdag, september.
Interface: (e.g. IDictionary) Specification class Appl{ ---- IDictionary dic; dic= new XXX(); application class: Dictionary SortedDictionary ----
Openen en Opslaan class Tekst : Form { } TextBox invoer; void lees (string naam) { } void schrijf (string naam) { } StreamReadersr = new StreamReader (naam);
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Generics Generics vs. heterogeneous collections Doing your own generics FEN 2014UCN Teknologi/act2learn1.
C# Collections & Generics C#.NET Software Development Version 1.0.
Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
UNCA CSCI September, 2001 These notes were prepared by the text’s author Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright.
Data Structures and Collections Principles.NET: –Two libraries: System.Collections System.Collections.Generics FEN 2014UCN Teknologi/act2learn1 Deprecated.
PRINCIPLES OF OBJECT ORIENTED DESIGN S.O.L.I.D. S.O.L.I.D Principles What is SOLID?  Acrostic of 5 Principles:  The Single Responsibility Principle.
(2.2) Hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en methode using Android.OS; using Android.App; using Android.Widget;
Generics & Collection Classes Version 1.0. Topics Generic Methods and Classes Generic Collection Classes List Enumerators Queue Stack LinkedList.
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
Module 13: Properties and Indexers. Overview Using Properties Using Indexers.
Chapter  Array-like data structures  ArrayList  Queue  Stack  Hashtable  SortedList  Offer programming convenience for specific access.
1 New Features in C# 2.0 Generic Types Iterators Simplified Delegates Anonymous Methods Partial Types Various © University of Linz, Institute for System.
Module 5: Programming with C#. Overview Using Arrays Using Collections Using Interfaces Using Exception Handling Using Delegates and Events.
8. Hafta İçeriği ArrayList TheArrayList class supports dynamic arrays, which can grow or shrink as needed. In C#, standard arrays are of a fixed length,
Week 15 – Monday.  What did we talk about last time?  Tries.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 2 nd Lecture Pavel Ježek
Advanced .NET Programming I 2nd Lecture
Computing with C# and the .NET Framework
Chapter 4 The easy stuff.
Gameprogrammeren: Klassen en objecten in Painter
string versus array Klasse Type met speciale syntax Indexer -notatie
Voorbeeld-programma's
2e Deeltentamen Nagekeken werk ligt voor in de zaal (alfabetisch op achternaam) Neem het even mee, opg.13 wordt in het college besproken Discussies over.
Chapter 5: Programming with C#
Collections 24: Collections Programming C# © 2003 DevelopMentor, Inc.
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים
Top Ten Words that Almost Rhyme with “Peas”
Road Map CS Concepts Data Structures Java Language Java Collections
Collection types/Anders Børjesson
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים
Data Structures and Database Applications Arrays And Lists
Introduction to Programming
Compiler Design First Lecture.
Gameprogrammeren: Game states
Fundaments of Game Design
Basic Collections.
鄭士康 國立台灣大學 電機工程學系/電信工程研究所/ 資訊網路與多媒體研究所
Advanced .NET Programming I 3rd Lecture
Chengyu Sun California State University, Los Angeles
Presentation transcript:

(H9.1) CirkelKlikker ARRAY int x, y; [ ] int n=0; void klik(object o, MouseEA mea) { } this.x = mea.X; this.y = mea.Y; this.Invalidate(); [n] [n] n++; void teken(object o, PaintEA pea) { } Graphics gr = pea.Graphics; ARRAY for (int t=0; t<n; t++) gr.FillEllipse(Brushes.Black, this.x , this.y , 15, 15 ); [t] [t]

Arrays Array: rij genummerde variabelen declaratie van een array tabel 1 2 3 4 length 5 int [ ] tabel; tabel = new int [5]; creëren van het eigenlijke array-object

Twee-dimensionale array tabel 5 3 length int [ , ] tabel; 1 2 tabel = new int [5,3]; 3 4 tabel.GetLength(0) tabel.GetLength(1) 1 2

LetterTeller class LetterTeller : Form TextBox invoer Label uitvoer StaafDiagram diagram class StaafDiagram : UserControl class TurfTab

Letterteller hoofdklasse class LetterTeller : Form { TextBox invoer; Label uitvoer; StaafDiag diagram; LetterTeller() { invoer = new TextBox(); invoer.MultiLine = true; uitvoer = new Label(); diagram = new StaafDiag(); } invoer . TextChanged += this.Bereken; void Bereken(object o, EventArgs ea) { } TurfTab tabel = new TurfTab(); tabel.Turf ( invoer.Text ); uitvoer.Text = tabel.ToString() ; diagram.Waardes = tabel.Waardes ; }

De klasse TurfTab public class TurfTab { private int [ ] tellers; private int totaal; public TurfTab ( ) { } tellers = new int [26]; public void Turf (string s) { } for (int t=0; t<s.Length; t++) this.turf ( s[t] ); }

De klasse TurfTab public class TurfTab { private int [ ] tellers; private int totaal; private void turf (char c) { } if (c>='A' && c<='Z') { } tellers [ ] ++; totaal++; c - 'A' if (c>='a' && c<='z') { tellers [ c - 'a' ] ++; totaal++; } }

De klasse TurfTab public class TurfTab { private int [ ] tellers; private int totaal; een eigen property! public int Totaal { get { } "mini- methodes" "mini- methodes" return totaal; set { } totaal = value; } }

geen set-minimethode: De klasse TurfTab public class TurfTab { private int [ ] tellers; private int totaal; een eigen property! public int Totaal { get { } "mini- methodes" "mini- methodes" return totaal; geen set-minimethode: read-only property set { } totaal = value; } }

…is eigenlijk overbodig! Array …is eigenlijk overbodig! array: oject dat een rij waarden bevat, met speciale notaties List: array “ingepakt” in een klasse, met standaard notaties uitgebreide Declaratie Creatie Opvragen Wijzigen Lengte String [ ] a; List<String> a; List a; a = new String[10]; a = new List(); a = new List<String>(); ……a[5]…… ……a[5]…… …a.Get(5)… a[5] = ……; a[5] = ……; a.Set(5,…); …a.Length… …a.Count… Invoegen Achtervoegen a.Insert(5,…); a.Add(…);

Voorbeeld: array class Voorbeeld : Form { } TextBox in; Button b; String [] alles; int n; Voorbeeld ( ) { } void teken(object o, PEA pea) { } in = new TextBox(); b = new Button(); b.Click += klik; this.Paint += teken; int y = 50; for (int t=0; t<n; t++) { pea.Graphics.DrawString( alles[t], ......, y ); y+=20; } alles = new String[100]; n = 0; void klik(object o, AE ae) { } if (n<100) { String s = in.Text; alles[n] = s; n++; this.Invalidate(); }

List Voorbeeld: array class Voorbeeld : Form { } TextBox in; Button b; List<String> alles; String [] alles; int n; Voorbeeld ( ) { } void teken(object o, PEA pea) { } in = new TextBox(); b = new Button(); b.Click += klik; this.Paint += teken; int y = 50; for (int t=0; t<n; t++) { pea.Graphics.DrawString( alles[t], ......, y ); y+=20; } alles.Count ;t++) alles[t] alles = new List<String>( ); alles = new String[100]; n = 0; void klik(object o, AE ae) { } if (n<100) { String s = in.Text; alles[n] = s; n++; alles.Add(s); this.Invalidate(); }

Hoe is List gemaakt? class List<Elem> { } Elem [] elems; int n; { elems = new Elem[10]; n = 0; } void Add(Elem e) { } if (n>=elems.Length) vergroot(); elems[n]=e; n++; Elem Get (int p) { return elems[p]; } this [int p] private void vergroot() { } get { } Elem [] kopie; kopie= new Elem[2*n]; for (int t=0; t<n; t++) kopie[t] = elems[t] int Count { get { return n; } } elems = kopie;

Kan het ook anders? class List<Elem> { } Elem [] elems; int n; { elems = new Elem[10]; n = 0; } void Add(Elem e) { } if (n>=elems.Length) vergroot(); elems[n]=e; n++; Elem Get (int p) { return elems[p]; } this [int p] private void vergroot() { } get { } Elem [] kopie; kopie= new Elem[2*n]; for (int t=0; t<n; t++) kopie[t] = elems[t] int Count { get { return n; } } elems = kopie; n*=2;

Ja: je kunt een List maken zonder dat een array nodig is class AndereList<Elem> { } …… 3 null © AndereList<Elem>() { …… } Elem this[int p] { …… } int Count { …… } void Add(Elem e) { …… }

Ja: je kunt een List maken zonder dat een array nodig is class AndereList<Elem> { } …… null © AndereList<Elem>() { …… } 3 Elem this[int p] { …… } int Count { …… } void Add(Elem e) { …… }

Ja: je kunt een List maken zonder dat een array nodig is class AndereList<Elem> { } : IList interface IList<Elem> { } …… int Count { get; } ; void Clear(); void Add(Elem e) ; Elem this [int p] { get; set; }; void Insert (int p, Elem e); © AndereList<Elem>() { …… } Elem this[int p] { …… } int Count { …… } Klasse implementeert de methodes Interface specificeert de methodes void Add(Elem e) { …… }

Namespace System.Collections.Generic interface diverse implementaties IList List Andere List

Voorbeeld: List class Voorbeeld : Form { } TextBox in; Button b; List<String> alles; IList<String> alles; Voorbeeld ( ) { } void teken(object o, PEA pea) { } in = new TextBox(); b = new Button(); b.Click += klik; this.Paint += teken; int y = 50; for (int t=0; t<n; t++) { pea.Graphics.DrawString( alles[t], ......, y ); y+=20; } alles.Count ;t++) alles = new List <String>( ); alles[t] alles = new String[100]; n = 0; AndereList void klik(object o, AE ae) { } String s = in.Text; alles[n] = s; n++; alles.Add(s); this.Invalidate();

Varianten van List genummerd zonder dubbele ICollection IList zonder dubbele ISet interface ICollection<Elem> { void Add(Elem x); bool Remove(Elem x); bool Contains(Elem x); int Count { get; }; void Clear(); } interface IList<Elem> : ICollection<Elem> { Elem this[int n] { get; set; } ; int IndexOf(Elem x); void Insert(int n, Elem x); void RemoveAt(int n); }

Implementaties van Collections ICollection LinkedList Queue Stack IList List ISet HashSet SortedSet IDictionary SortedList Sorted Dictionary

Voorbeeld: Collection class Voorbeeld : Form { } TextBox in; Button b; List<String> alles; IList<String> alles; ICollection<String> alles; Voorbeeld ( ) { } void teken(object o, PEA pea) { } in = new TextBox(); b = new Button(); b.Click += klik; this.Paint += teken; int y = 50; for (int t=0; t<n; t++) { pea.Graphics.DrawString( alles[t], ......, y ); y+=20; } alles.Count ;t++) alles = new List <String>( ); alles[t] alles = new String[100]; n = 0; LinkedList void klik(object o, AE ae) { } String s = in.Text; alles[n] = s; n++; alles.Add(s); this.Invalidate();

Hoe doorloop je een Collection? List Collection for (int t=0; t<alles.Count; t++) doeIetsMet( alles[t] ); foreach (String s in alles) doeIetsMet( s ); opdracht for ) ( expr ; type expr in naam foreach ( ) opdracht

Voorbeeld: Collection class Voorbeeld : Form { } TextBox in; Button b; List<String> alles; IList<String> alles; ICollection<String> alles; Voorbeeld ( ) { } void teken(object o, PEA pea) { } in = new TextBox(); b = new Button(); b.Click += klik; this.Paint += teken; int y = 50; foreach ( String s in alles ) for (int t=0; t<n; t++) { pea.Graphics.DrawString( alles[t], ......, y ); y+=20; } alles.Count ;t++) alles = new List <String>( ); alles[t] s alles = new String[100]; n = 0; LinkedList void klik(object o, AE ae) { } String s = in.Text; alles[n] = s; n++; alles.Add(s); this.Invalidate();