Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying .NET 4.0 Generics Beginner's Guide
  • Table Of Contents Toc
.NET 4.0 Generics Beginner's Guide

.NET 4.0 Generics Beginner's Guide

By : Sudipta Mukherjee
4.6 (14)
close
close
.NET 4.0 Generics Beginner's Guide

.NET 4.0 Generics Beginner's Guide

4.6 (14)
By: Sudipta Mukherjee

Overview of this book

Generics were added as part of .NET Framework 2.0 in November 2005. Although similar to generics in Java, .NET generics do not apply type erasure but every object has unique representation at run-time. There is no performance hit from runtime casts and boxing conversions, which are normally expensive..NET offers type-safe versions of every classical data structure and some hybrid ones. This book will show you everything you need to start writing type-safe applications using generic data structures available in Generics API. You will also see how you can use several collections for each task you perform. This book is full of practical examples, interesting applications, and comparisons between Generics and more traditional approaches. Finally, each container is bench marked on the basis of performance for a given task, so you know which one to use and when. This book first covers the fundamental concepts such as type safety, Generic Methods, and Generic Containers. As the book progresses, you will learn how to join several generic containers to achieve your goals and query them efficiently using Linq. There are short exercises in every chapter to boost your knowledge. The book also teaches you some best practices, and several patterns that are commonly available in generic code. Some important generic algorithm definitions are present in Power Collection (an API created by Wintellect Inc.) that are missing from .NET framework. This book shows you how to use such algorithms seamlessly with other generic containers. The book also discusses C5 collections. Java Programmers will find themselves at home with this API. This is the closest to JCF. Some very interesting problems are solved using generic containers from .NET framework, C5, and PowerCollection Algorithms ñ a clone of Google Set and Gender Genie for example! The author has also created a website (http://www.consulttoday.com/genguide) for the book where you can find many useful tools, code snippets, and, applications, which are not the part of code-download section
Table of Contents (20 chapters)
close
close
.NET 4.0 Generics
Credits
Foreword
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
2
Lists
4
LINQ to Objects
2
Migration Cheat Sheet
chevron up

Appendix B. Migration Cheat Sheet

STL to Generics

STL

.NET Generics class

Comments

vector

List<T>

 

deque

LinkedList<T>

deque allows addition and deletion at both ends in constant time.

list

LinkedList<T>

list also allows addition and deletion at both ends in constant time. Thus, that is what is best mapped to these two containers.

stack

Stack<T>

 

Queue

Queue<T>

 

priority_queue

Not available

You can use PriorityQueue<TKey,TValue> described in Chapter 3, Dictionaries.

set

HashSet<T>, SortedSet<T>

Use SortedSet<T> if you always want the set to be sorted.

multiset

Not available. You can use OrderedBag from PowerCollections.

Can be modeled as Dictionary<T,int> or SortedDictionary<T,int> if you want entries to be sorted.

map

Dictionary<TKey,TValue>

SortedDictionary <TKey,TValue>

Use SortedDictionary<TKey, TValue> if you always want entries to be sorted.

multimap

Dictionary<TKey, List<TValue>>

You can also use OrderedBag in PowerCollection

bitset

List<bool>

 

JCF to Generics

Java Collection Framework (JCF)

.NET Generics class

Comments

LinkedList

LinkedList<T>

 

ArrayList

Not available

Use ArrayList<T> in C5 Collections.

HashSet

HashSet<T>

 

TreeSet

Not available

Use TreeSet<T> in C5 Collections.

HashMap

Not available

Use HashDictionary <TKey,TValue> in C5 Collections.

TreeMap

Not available

Use TreeDictionary <TKey,TValue> in C5 Collections.

LinkedHashMap

HashDictionary<TKey,TValue>

 

Vector

List<T>

 

HashTable

Dictionary<TKey,TValue>

 

SortedSet

SortedSet<T>

 

SortedMap

SortedDictionary<TKey,TValue>

 

PriorityQueue

Not available

Use PriorityQueue <TKey,TValue> described in Chapter 3, Dictionaries.

Deque

LinkedList<T>

 

Power Collections to Generics

Power Collection Class

.NET Generics class

Comments

Pair<TKey,TValue>

KeyValuePair<TKey,TValue>

 

Set<T>

Set<T>

 

MultiDictionary <TKey,TValue>

Not Available

You can use the MultiDictionary we have created in Chapter 3, Dictionaries.

OrderedSet<T>

SortedSet<T>

 

Bag<T>

List<T>

 

OrderedBag<T>

Not available

This is basically a sorted list where duplicates are allowed.

Deque<T>

List<T>

You can add/remove from both ends of a List<T>.

Triple<T1,T2,T3>

Tuple<T1,T2,T3>

This is a special case of a Tuple.

BigList<T>

List<T>

 

.NET 1.1 to Generics .NET 4.0

Non-generic collection

Generic collection (available from .Net 2.0)

Thread-safe generic collection

ArrayList

List<T>

ConcurrentBag<T>

Stack

Stack<T>

ConcurrentStack<T>

Queue

Queue<T>

ConcurrentQueue<T>

HashTable

Dictionary<TKey, TValue>

ConcurrentDictionary<T>

SortedList

SortedList<TKey, TValue>

ConcurrentDictionary<TKey,TValue>

BitArray

List<bool>

ConcurrentBag<bool>

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
.NET 4.0 Generics Beginner's Guide
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon