Book Image

Cross-platform UI Development with Xamarin.Forms

By : Paul Johnson
Book Image

Cross-platform UI Development with Xamarin.Forms

By: Paul Johnson

Overview of this book

Table of Contents (22 chapters)
Cross-platform UI Development with Xamarin.Forms
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
In the Beginning…
Index

.NET generics


With the advent of .NET 2.0, this problem was solved; Microsoft introduced generics to the mix. The generic classes are instantiated once and then you can add to them as many times as you like. The framework itself does the memory management for the list, so they can be considered as an ever-extendable array.

In which case, why are they called generics as arrays have a definite type (string, int, byte and so on)? The answer to that is the type argument. A .NET generic takes a generic type (typically referred to as T). This T can be anything—even another generic (for example, there is nothing to stop you from having List<Dictionary<T, List<U>>>, the caveat being that T and U will need to be defined somewhere).

This obviously will mean that you can create not only a list of strings, but a list of classes, structs, UI objects, and pretty much anything you want. Unless the generic has a global scope or static type, when the class that the generic is defined in goes...