Day 9 – Generics

The Source Code

This post is part of my Dot Net On Linux posts. All the source code is available on GitHub here

Intro

Generics allow code to be come for “generic” by providing the ability to have parameter types as ‘type parameter’.

You can read more on my How To here.

You can also find my Generics Cheat Sheet here.

Code Examples

Mean Calculator

Probably not the best usage of generics but an example to calculate the mean average from any set of numbers

Enumerator or Number Parser

An example of how to parse any string to an Enumerator or Number with overrides to allow a default value when not passed, throw an exception or to return the types default value

Serialize and De-serialize any class to and from XML

An example of how to serialize and de-serialize any class to and from XML with one method call.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s