Presentation is loading. Please wait.

Presentation is loading. Please wait.

C# Data Structures AND Generics By Michael and Miles.

Similar presentations


Presentation on theme: "C# Data Structures AND Generics By Michael and Miles."— Presentation transcript:

1 C# Data Structures AND Generics By Michael and Miles

2 Overview What are data structures? Benefits and uses What are generics? Benefits and uses Live samples Summary

3 Data Structures 1. Collections of data 2. Fetch and store 3. type of data structure depends on situation 4. Examples Array, arraylist, list, linkedlist, stack, queue, dictionary, etc. 5. Most basic is the array

4

5 Arrays 1. Most commonly used data structure 2.Contents are stored in contiguous memory 3.All data must be same type Pros: Quick direct access (for loop) Easy to use Cons: Searching is proportional to data size Cannot resize array

6 What are generics? 1.One of the most powerful features introduced in C# 2.0 2.System.Collections.Generic… 3.Mainly used with collections/data structures 4.Type safety 5.Generic methods 1.Similar operations on different data types

7 1.Pros Type safety Reduces the need for type casting – less run-time errors Performance boost – No boxing/unboxing (less code) maximize code reuse 2.Cons Can get complex Learning curve

8 List 1.Similar to arrays – 2.A generic data structure 3.Type-safe 4. Dynamic resizing -.Add().Insert().Remove() 5.Built in search methods 6.flexibility

9 Like a circular array First come first serve Insertions made at the tail Pros: Good for processing Cons: Not searchable Not many uses Queues

10 Dictionaries Key value pairs Data is unordered Easy lookups Type safe (generic)

11 Drawbacks of non-generic data structures Data stored as type object – Casting: conversion of data types double x = 1234.7; int a; a = (int)x; // cast double to int – Limited type checking * Increased Overhead – More work to getting something done

12 “CANNOT IMPLICITLY CONVERT TYPE OBJECT TO INT”

13 And then there’s LINQ Write queries (similar to SQL queries) Retrieve info from many data structures – Arrays, List<> etc. Quick example http://msdn.microsoft.com/en -us/library/bb907066.aspx

14 Summary Types of Structures Generics – What they are/how to use Practical uses

15 Questions/ comments/ compliments?


Download ppt "C# Data Structures AND Generics By Michael and Miles."

Similar presentations


Ads by Google