0% found this document useful (0 votes)
62 views44 pages

Florin Olariu: "Alexandru Ioan Cuza", University of Iași Department of Computer Science

This document provides an introduction and overview of .NET and some key .NET concepts including generic dictionaries, LINQ, and interview questions. The presentation covers what generic dictionaries are and how to declare, initialize, and manipulate them. It demonstrates generic dictionaries in code. LINQ is introduced as a way to execute queries against data sources from .NET code. The two ways to write LINQ queries - query syntax and method syntax - are explained and demonstrated. Lambda expressions are discussed as they relate to LINQ. Best practices for using LINQ with collections are also provided. Finally, the document mentions it will cover interview questions and Entity Framework Core in future sections.

Uploaded by

Gigi Florica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views44 pages

Florin Olariu: "Alexandru Ioan Cuza", University of Iași Department of Computer Science

This document provides an introduction and overview of .NET and some key .NET concepts including generic dictionaries, LINQ, and interview questions. The presentation covers what generic dictionaries are and how to declare, initialize, and manipulate them. It demonstrates generic dictionaries in code. LINQ is introduced as a way to execute queries against data sources from .NET code. The two ways to write LINQ queries - query syntax and method syntax - are explained and demonstrated. Lambda expressions are discussed as they relate to LINQ. Best practices for using LINQ with collections are also provided. Finally, the document mentions it will cover interview questions and Entity Framework Core in future sections.

Uploaded by

Gigi Florica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Introduction to .

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

 Generic dictionaries
 Demo
 LINQ
 Demo
 Interview questions
What’s next …

 Entity Framework Core


Generic dictionaries
Generic dictionaries

 What is a dictionary?
 How can we manipulate a dictionary?
Generic dictionaries

 What is a dictionary?

It is a data structure that enables us to access an element based on a


specified key.
Generic dictionaries

 What is a dictionary?

It is a data structure that enables us to access an element based on a


specified key.
It is a strongly typed collection of keys and values.
Generic dictionaries

 What is a dictionary?

It is a data structure that enables us to access an element based on a


specified key.
It is a strongly typed collection of keys and values.
 Key
Generic dictionaries

 What is a dictionary?

It is a data structure that enables us to access an element based on a


specified key.
It is a strongly typed collection of keys and values.
 Key
 Must be unique
Generic dictionaries

 What is a dictionary?

It is a data structure that enables us to access an element based on a


specified key.
It is a strongly typed collection of keys and values.
 Key
 Must be unique
 Must not be changed
Generic dictionaries

 What is a dictionary?

It is a data structure that enables us to access an element based on a


specified key.
It is a strongly typed collection of keys and values.
 Key
 Must be unique
 Must not be changed
 Cannot be null
Generic dictionaries

 Declaration
Generic dictionaries

 Declaration

Dictionary<TKey, TValue>
Generic dictionaries

 Declaration

Dictionary<TKey, TValue>
 Samples

Dictionary<int, int>
Dictionary<int, string>
Dictionary<string, Product>
Generic dictionaries

 Initialization
Dictionary<string, string> states;
states = new Dictionary<string, string>();

Dictionary<string, string> states = new Dictionary<string, string>();

var states = new Dictionary<string, string>();


Generic dictionaries

 Manipulating a dictionary
states.Add("NY", "New York");

var states = new Dictionary<string, string>


{
{"NY", "New York"},
{ "CA", "California"}
};
states.Remove("CA");
Generic dictionaries

 Demo
Generic dictionaries

 Performance
Generic dictionaries

 Performance
 Many collection classes offer the same functionality as others; for example,
SortedList offers nearly the same features as SortedDictionary.
Generic dictionaries

 Performance
 Many collection classes offer the same functionality as others; for example,
SortedList offers nearly the same features as SortedDictionary.
 However, often there’s a big difference in performance. Whereas one collection
consumes less memory, the other collection class is faster with retrieval of
elements.
Generic dictionaries

 Details about big O algorithm complexity in attached pdf for the course.
LINQ
LINQ

 Intro
 Building a LINQ query using Query syntax - Demo
 Building a LINQ query using Method syntax - Demo
 Lambda expression in action - Demo
 Using LINQ with collections
LINQ

 Stands from Language INtegrated Query


LINQ

 Stands from Language INtegrated Query


 Definition
LINQ

 Stands from Language INtegrated Query


 Definition
 A way to execute queries against a data source directly from .NET
LINQ

 Stands from Language INtegrated Query


 Definition
 A way to execute queries against a data source directly from .NET
 Data sources :
 LINQ to objects => should implement an IEnumerable interface
 LINQ to SQL => works with SQL databases
 LINQ with Entities => works with Entity Framework
 LINQ to XML => works with any XML Document
 …
LINQ

 There are 2 ways to express queries in LINQ:


LINQ

 There are 2 ways to express queries in LINQ:


 Query syntax:
LINQ

 There are 2 ways to express queries in LINQ:


 Query syntax:
var product = from p in products
where p.Name == productName
select p;
 Method syntax
LINQ

 There are 2 ways to express queries in LINQ:


 Query syntax:
var product = from p in products
where p.Name == productName
select p;
 Method syntax
var product = products.Where(p => p.Name ==
productName).FirstOrDefault(); or
LINQ

 There are 2 ways to express queries in LINQ:


 Query syntax:
var product = from p in products
where p.Name == productName
select p;
 Method syntax
var product = products.Where(p => p.Name ==
productName).FirstOrDefault(); or
var product = products.FirstOrDefault(p => p.Name ==
productName);
LINQ

 Delegate
LINQ

 Delegate
 Is a type that represents a reference to a method with a specific parameter
list and a return type.
LINQ

 Delegate
 Is a type that represents a reference to a method with a specific parameter
list and a return type.
LINQ

 Delegate
 Is a type that represents a reference to a method with a specific parameter
list and a return type.
LINQ

 Lambda expression
LINQ

 Lambda expression
 Is a method that can be passed as an argument to a method when that
argument is expecting a delegate type.
LINQ

 Demo – Query syntax vs Method syntax and Lambda expressions


LINQ

 LINQ with collections

DO AVOID
Use LINQ! Iterating the collections multiple
times
Consider using method syntax over Use FirstOrDefault and LastOrDefault
query syntax instead of First and Last
Wait to cast a result after all queries
are defined
Interview questions
One more thing…

 “Always code as if the guy who ends up maintaining your code will be a
violent psychopath who knows where you live” 
― John Woods
Questions

 Do you have any other questions?


Thanks!
See you next time! 

You might also like