1 / 15

C# Data Structures AND Generics

C# Data Structures AND Generics. By Michael and Miles. Overview. What are data structures? Benefits and uses What are generics? Benefits and uses Live samples Summary. Data Structures. 1. Collections of data 2. Fetch and store 3. type of data structure depends on situation

tavia
Download Presentation

C# Data Structures AND Generics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Arrays 1. Most commonly used data structure • Contents are stored in contiguous memory • 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

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

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

  7. List<T> • Similar to arrays – • A generic data structure • Type-safe • Dynamic resizing - .Add() .Insert() .Remove() • Built in search methods • flexibility

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

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

  10. Drawbacks ofnon-genericdata 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

  11. “CANNOT IMPLICITLY CONVERT TYPE OBJECT TO INT”

  12. 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

  13. Summary Types of Structures Generics • What they are/how to use Practical uses

  14. Questions/comments/compliments?

More Related