Presentation is loading. Please wait.

Presentation is loading. Please wait.

MIS Professor Sandvig MIS 324 Professor Sandvig

Similar presentations


Presentation on theme: "MIS Professor Sandvig MIS 324 Professor Sandvig"— Presentation transcript:

1 MIS 324 -- Professor Sandvig MIS 324 Professor Sandvig
2/24/2019 C# Collections MIS 324 Professor Sandvig

2 Overview What are collections Arrays Language Integrated Query (LINQ)
Sort & filter collections Similar to SQL Generic List<>

3 What are Collections Collections store multiple data values
Frequently work with collections: Database records List of products List of people Shopping cart Cookies Web form values Etc.

4 What Are Collections Arrays .NET library namespaces
C# feature Simple Limited functionality .NET library namespaces System.Collections System.Collections.Generic Classes for managing collections of data

5 What are Collections Select collection type based on desired behavior & performance Many choices: Array Queue Stack Dictionary List<> Sorted List Etc.

6 What are Collections A few types of collections: Collection Best for
Dictionary Fast lookups Sorted list Items sorted on Insert List General use Stack Last in First Out (LIFO) Queue First in First Out (FIFO)

7 Array Simple collection type Basic C# language feature
Limited features No sorting No filtering Limited to C# data types

8 Array Advantages Disadvantages Simple Basic features:
Iterate, retrieve values, find value Disadvantages Limited to C# data types String, Int, Double, etc. Size fixed when initialized

9 Collections Namespaces
.NET library namespaces System.Collections System.Collections.Generic Provide classes for managing data Lookup (fast) Sort Filter Find Etc.

10 Generic Collections System.Collections.Generic namespace
Strongly typed! Faster Used extensively in MVC Retain datatypes defined in model .NET Library Documentation

11 Generic Collections Why “generic”? Declare type when create collection
Items in collection can be any “generic” object Declare type when create collection List<int> myGenericList = new List<int>(); Generics can hold any object List<PersonModel> personList = new List<PersonModel>(); See code sample

12 MIS 324 -- Professor Sandvig
2/24/2019 Generic List<> List<> only collection used in MIS 324 Used in ViewModels Fonts States List<> has methods for sorting, finding, etc. Often use LINQ (Language Integrated Query) to query List

13 LINQ Language Integrated Query Query language built into C#
Use with any collection type Including database Capabilities similar to SQL Uses Lamda Syntax .where(collection => expression) Collection Examples

14 Summary Collections frequently used Generic Collections Strongly typed
Generic List<> used for most data lists


Download ppt "MIS Professor Sandvig MIS 324 Professor Sandvig"

Similar presentations


Ads by Google