Introduction to .
NET
Florin Olariu
“Alexandru Ioan Cuza”, University of Iași
Department of Computer Science
Agenda
OOP in .NET Core
Arrays
Demo
Generic list
Demo
What’s Next
Interview questions
OOP in .NET Core
Inheritance
OOP in .NET Core – inheritance
OOP in .NET Core - inheritance
OOP in .NET Core - polymorphism
Polymorphism
OOP in .NET Core - polymorphism
OOP in .NET Core - polymorphism
OOP in .NET Core - encapsulation
Encapsulation
OOP in .NET Core
Inheritance Polymorphism Encapsulation
OOP in .NET Core
"In the one and only true way. The object-oriented version of 'Spaghetti
code' is, of course, …."
OOP in .NET Core
"In the one and only true way. The object-oriented version of 'Spaghetti
code' is, of course, 'Lasagna code'."
- Roberto Waltman.
Arrays
Arrays
Definition
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
Definition
Is a fixed-size list of elements that can be accessed using a positional index
number
Sample:
Red “Salt” 2.21
White “Pepper” 3.43
Green “Onion” 5.01
Blue “Garlic” 3.20
Arrays
Definition
Is a fixed-size list of elements that can be accessed using a positional index
number
Sample:
0 Red 0 “Salt” 2.21
1 White 1 “Pepper” 3.43
2 Green 2 “Onion” 5.01
3 Blue 3 “Garlic” 3.20
Arrays
Definition
Samples
Declaring and populating an array
Arrays
Definition
Samples
Declaring and populating an array
Declaring an array:
Red string[] colors;
White
Green
Blue
Arrays
Definition
Samples
Declaring and populating an array
Declaring an array: Initializing an array:
Red
string[] colors; string[] colors;
White
colors = new string[4];
Green
string[] colors = new string[4];
Blue
var colors = new string[4];
Arrays
Definition
Samples
Declaring and populating an array
Populating an array
Arrays
Definition
Samples
Declaring and populating an array
Populating an array
var colors = new string[4];
colors[0] = “Red”;
colors[1] = “White”;
colors[2] = “Green”;
colors[3] = “Blue”;
Arrays
Best practices
Do Avoid
Use arrays when the size is known at Do not use arrays when the data
the design time comes from a database call
For an array name use ‘pluralization’
=> Colors
Arrays
Demo
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 Strongly typed
Generic List
Arrays vs Generic List
Arrays Generic List
Strongly typed Strongly typed
Fixed length Expandable
Generic List
Arrays vs Generic List
Arrays Generic List
Strongly typed Strongly typed
Fixed length Expandable
The is no ability to add/remove Can add, insert or remove elements
elements
Generic List
Arrays vs Generic List
Arrays Generic List
Strongly typed Strongly typed
Fixed length Expandable
The is no ability to add/remove Can add, insert or remove elements
elements
Multi-dimensional One-dimensional
Generic List
Declaring and populating Generic Lists
Generic List
Declaring and populating Generic Lists
Generic List
Declaring and populating Generic Lists
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
List/for: 1971ms (589725196)
Array/for: 1864ms (589725196)
List/foreach: 3054ms (589725196)
Array/foreach: 1860ms (589725196)
Generic List
Demo
What’s next …
Generic dictionaries
Generic collection interfaces
LINQ
Interview questions
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!