Introduction to .NET Florin Olariu

Slides:



Advertisements
Similar presentations
Java POWERED BY: ARVIND DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING RADHA GOVIND GROUP OF INSTITUTIONS,MEERUT.
Advertisements

Static Members, Structures, Enumerations, Generic Classes, Namespaces Learning & Development Team Telerik Software Academy.
Arrays. A group of data with same type stored under one variable. It is assumed that elements in that group are ordered in series. In C# language arrays.
Alice in Action with Java
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Arrays and ArrayLists.
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Based on material from Telerik Corporation.
Lists Ellen Walker CPSC 201 Data Structures Hiram College.
Object Oriented Programming Lecture 5: Arrays and Strings Mustafa Emre İlal
Lecturer : Sakuni Sellapperuma. Introduction An array is a container object that holds a fixed number of values of a single type. The length of an array.
CS-2852 Data Structures LECTURE 7A Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Arrays, Lists, Stacks, Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
Arrays and ArrayLists. int numbers[] = new int[10]; numbers Other ways to declare the same array 1) int[] numbers = new.
More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework 1 CS300.
Creating and Using Class Methods. Definition Class Object.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
COMP More About Arrays Yi Hong June 05, 2015.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
2 Arrays Array is a data structure that represents a collection of the same type of data. A "fixed length list".
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 10.
Today… Loops and Drawing, Cont. –Two slightly more advanced demos. Collections Overview. Winter 2016CISC101 - Prof. McLeod1.
Introduction to.NET Florin Olariu “Alexandru Ioan Cuza”, University of Iai Department of Computer Science.
Processing Sequences of Elements
Lecture 10 Collections Richard Gesick.
Java Arrays and ArrayLists COMP T1 #5
Introduction to .NET Florin Olariu
Introduction to .NET Florin Olariu
Sixth Lecture ArrayList Abstract Class and Interface
CHAPTER 22 LISTS AND ARRAYS 1.
Repeating Code Multiple Times
Arrays, Lists, Stacks, Queues
Introduction to LINQ and Generic Collections
Processing Variable-Length Sequences of Elements
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Software Development Java Collections
Game Extras Pepper.
[Array, Array, Array, Array]
Inheritance & Polymorphism
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
Array List Pepper.
MIS Professor Sandvig MIS 324 Professor Sandvig
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Arrays.
CS 302 Week 8 Jim Williams, PhD.
Chapter 8 Slides from GaddisText
Data Structures and Database Applications Arrays And Lists
Arrays and Collections
Object Oriented Programming in java
CSCI 3328 Object Oriented Programming in C# Review: Exam II
Multidimensional Arrays
Cs212: Data Structures Computer Science Department Lecture 2: Arrays.
Topics discussed in this section:
[Array, Array, Array, Array]
CS2011 Introduction to Programming I Arrays (I)
MSIS 655 Advanced Business Applications Programming
int [] scores = new int [10];
Module8 Multi-dimensional Array
Multidimensional array
Managing Collections of Data
Collections Framework
MIS Professor Sandvig MIS 324 Professor Sandvig
Introduction to Data Structure
Object Oriented Programming
Java SE 7 One and Multi Dimensional Arrays Module 6
Introduction to .NET Florin Olariu
Fundaments of Game Design
CIS 110: Introduction to Computer Programming
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Presentation transcript:

Introduction to .NET Florin Olariu “Alexandru Ioan Cuza”, University of Iași Department of Computer Science

Agenda Arrays Demo Generic list What’s Next Interview questions

Arrays

Arrays Definition Declaring and populating an array Samples Declaring and populating an array Using collection initializers Retrieving an element from an array Iterating an array Using array methods Best practices Demo

Arrays Definition

Arrays Definition Is a fixed-size list of elements that can be accessed using a positional index number

Arrays “Salt” 2.21 Red Definition White “Pepper” 3.43 “Onion” 5.01 Is a fixed-size list of elements that can be accessed using a positional index number Sample: Red White Green Blue “Salt” 2.21 “Pepper” 3.43 “Onion” 5.01 “Garlic” 3.20 Notes: 1. In arrays index is “0-based”. 2. Arrays are fixed size.(we will define the size of an array when this is initialized – once is initialized the size cannot be adjusted)

Arrays Definition 1 2 3 Red White Green Blue 1 2 3 “Salt” 2.21 Is a fixed-size list of elements that can be accessed using a positional index number Sample: 1 2 3 Red White Green Blue 1 2 3 “Salt” 2.21 “Pepper” 3.43 “Onion” 5.01 “Garlic” 3.20 Notes: In arrays index is “0-based”.

Arrays Definition Samples Declaring and populating an array

Arrays Red Definition White Declaring and populating an array Green Samples Declaring and populating an array Declaring an array: string[] colors; Red White Green Blue

Arrays Red White Green Blue Definition Samples Declaring and populating an array Declaring an array: Initializing an array: string[] colors; string[] colors; colors = new string[4]; string[] colors = new string[4]; var colors = new string[4]; Red White Green Blue An array is a reference type. In this case we should use: “new” keyword for initialization.

Arrays Definition Declaring and populating an array Samples

Arrays Definition Declaring and populating an array Samples var colors = new string[4]; colors[0] = “Red”; colors[1] = “White”; colors[2] = “Green”; colors[3] = “Blue”; An array is a reference type. In this case we should use: “new” keyword for initialization.

Arrays Best practices Do Avoid Use arrays when the size is known at the design time Do not use arrays when the data comes from a database call For an array name use ‘pluralization’ => Colors

Arrays Demo Working with arrays Note: How to create a R# template for tests

Generic List

Generic List Definition Arrays vs Generic List Declaring and populating Generic Lists Using initializers Retrieving elements from Generic lists Iterating through a Generic List Demo

Generic List Definition It is a strongly typed list of elements that is accessed using a positional index number.

Generic List Arrays vs Generic List

Generic List Arrays vs Generic List Arrays Generic List

Generic List Arrays vs Generic List Arrays Generic List Strongly typed

Generic List Arrays vs Generic List Arrays Generic List Strongly typed Fixed length Expandable

Generic List Arrays vs Generic List Arrays Generic List Strongly typed Fixed length Expandable The is no ability to add/remove elements Can add, insert or remove elements

Generic List Arrays vs Generic List Arrays Generic List Strongly typed Fixed length Expandable The is no ability to add/remove elements Can add, insert or remove elements Multi-dimensional One-dimensional

Generic List Declaring and populating Generic Lists

Generic List Declaring and populating Generic Lists var cities = new List<string>(); cities.Add(" London"); cities.Add(" Paris"); cities.Add(" Milan");

Generic List Declaring and populating Generic Lists var cities = new List<string>{“London”, “Paris”, “Milan”}; This is using Collection initializer.

Generic List Frequently asked questions When is appropriate to use a generic list?

Generic List Frequently asked questions When is appropriate to use a generic list? Any time the application needs to manage a list of things What are the key differences between an array and a generic list?

Generic List Frequently asked questions When is appropriate to use a generic list? Any time the application needs to manage a list of things What are the key differences between an array and a generic list? An array is fixed length and can have multiple dimensions A generic list can have any length and provides methods to add, insert or remove elements Execution time

Generic List Frequently asked questions When is appropriate to use a generic list? Any time the application needs to manage a list of things What are the key difference between an array and a generic list? An array is fixed length and can have multiple dimensions A generic list can have any length and provides methods to add, insert or remove elements Execution time For this samples I used: List<int> list = new List<int>(6000000); The second number is a checksum to verify they all did the same work. static class Program { static void Main() Random rand = new Random(12345); for (int i = 0; i < 6000000; i++) list.Add(rand.Next(5000)); } int[] arr = list.ToArray(); int chk = 0; Stopwatch watch = Stopwatch.StartNew(); for (int rpt = 0; rpt < 100; rpt++) int len = list.Count; for (int i = 0; i < len; i++) chk += list[i]; watch.Stop(); Console.WriteLine("List/for: {0}ms ({1})", watch.ElapsedMilliseconds, chk); chk = 0; watch = Stopwatch.StartNew(); for (int i = 0; i < arr.Length; i++) chk += arr[i]; Console.WriteLine("Array/for: {0}ms ({1})", watch.ElapsedMilliseconds, chk); foreach (int i in list) chk += i; Console.WriteLine("List/foreach: {0}ms ({1})", watch.ElapsedMilliseconds, chk); foreach (int i in arr) Console.WriteLine("Array/foreach: {0}ms ({1})", watch.ElapsedMilliseconds, chk); Console.ReadLine(); List/for: 1971ms (589725196) Array/for: 1864ms (589725196) List/foreach: 3054ms (589725196) Array/foreach: 1860ms (589725196)

Generic List Demo Initialization, Add, Insert, Remove, RemoveAt;

What’s next … Generic dictionaries Generic collection interfaces LINQ

Interview questions Abstract classes vs Interfaces Boxing/Unboxing Immutable string

One more thing…  "Walking on water and developing software from a specification are easy…"

One more thing…   "Walking on water and developing software from a specification are easy if both are frozen." - Edward V Berard

Questions Do you have any other questions?

Thanks! See you next time! 