They are a type of data structure that contains code

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s more reusable. They are a type of data structure that contains code that remains the same. The data type of the parameters can change with each use. The usage within the data structure adapts to the different data type of the passed variables. Each time the generic is used, it can be customized for different data types without needing to rewrite any of the internal code. 2 Generics Example using System; using System.Collections; using System.Text; namespace { public class List<Template> : CollectionBase { public List() { } public Template this[int index] { get { return (Template)List[index]; } set { List[index] = value; } } public int Add(Template value) { return List.Add(value); } } public class Generics { public static void Main() { List<string> list1 = new List<string>(); // No boxing or casting necessary list1.Add("Hello World!"); } } } .NET Base Class Library This material is based on the original slides of Dr. Mark Sapossnek, Computer Science Department, Boston University, Mosh Teitelbaum, evoch, LLC, and Joe Hummel, Lake Forest College 3 Outline Introduction System Namespace Collection Classes I/O and Networking Threading and Synchronization...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online