About generics
.NET has a concept called generics and PowerShell, as a .NET language, can make use of generic types and methods.
Microsoft describes this as follows in an article with the same name as this section:
Generic classes and methods combine reusability, type safety, and efficiency in a way that their non-generic counterparts cannot.
(Source: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/generics)
The use of generic classes, or types, is common in the modern use of PowerShell.
Generic classes
.NET has the concept of a generic class; some of these are very common such as System.Collections.Generic.List<T>
, where T is a type that must be declared when the instance is created. For example:
[System.Collections.Generic.List[string]]::new()
Generic types avoid the cost of what is known as boxing. This is where a value is wrapped in an instance of System.Object
before it is stored.
The cost of boxing is...