Top "Generics" questions

Generics are a form of parametric polymorphism found in a range of languages, including .NET languages, Java, Swift, and Rust.

Casting array to IEnumerable<T>

Assume you have a basic Employee class as such: class Employee { public string Name; public int Years; public string Department; } …

c# arrays generics casting
What's the difference between SortedList and SortedDictionary?

Is there any real practical difference between a SortedList<TKey,TValue> and a SortedDictionary<TKey,TValue>? …

c# .net generics sortedlist sorteddictionary
Convert a generic list to an array

I have searched for this, but unfortunately, I don't get the correct answer. class Helper { public static <T> …

java generics
How to pass a class type as a function parameter

I have a generic function that calls a web service and serialize the JSON response back to an object. class …

swift generics type-inference
What are the differences between "generic" types in C++ and Java?

Java has generics and C++ provides a very strong programming model with templates. So then, what is the difference between …

java c++ generics templates language-features
Cannot implicitly convert type 'Int' to 'T'

I can call Get<int>(Stat); or Get<string>(Name); But when compiling I get: Cannot …

c# generics
Using the field of an object as a generic Dictionary key

If I want to use objects as the keys for a Dictionary, what methods will I need to override to …

.net generics dictionary
Calling generic method with a type argument known only at execution time

Edit: Of course my real code doesn't look exactly like this. I tried to write semi-pseudo code to make it …

c# linq generics reflection
Elegant way to combine multiple collections of elements?

Say I have an arbitrary number of collections, each containing objects of the same type (for example, List<int&…

c# linq generics collections
Making a generic property

I have a class that stores a serialized value and a type. I want to have a property/method returning …

c# .net generics properties