Questions tagged [generic-collections]

A collection that supports generic typing of its elements

Since java 1.5 (released in 2004), the JDK java.util.Collection interface is generic (typed).

Unless you're using an ancient version of java, the word "generic" in "generic collections" is redundant.

390 questions
2
votes
3 answers

Performance Hit? list of anonymous type to achieve something like this List (a multi-dimensional list of multiple types) in c#)

I am wondering about whether or not creating a list of an anonymous type is the best way to effectively create a list of multiple types as well as its effect on general performance and efficiency. Mainly I just want to know if there is a more…
2
votes
1 answer

Trying to make templates in C

I made a generic vector in C using macros. Is the concept viable or do I get a one-way trip to the bonfire for even thinking about it? #ifndef VECTOR_H #define VECTOR_H #define vector_at(vector, pos) ((vector).data[pos]) #define…
2
votes
1 answer

How to IEnumerable.GroupBy with 3 different "qualities" getting count in C# LINQ?

I want to group by a list of objects inherited from an abstract class by: Type of item in list (in this example MyAction or MyObservation) An integer attribute ClassId A string attribute Value And get a count out those groups. public abstract…
char m
  • 7,840
  • 14
  • 68
  • 117
2
votes
2 answers

Migrating legacy .NET collections to their generic counterparts

At the moment I'm working on a project that contains a fair amount of legacy code which includes the use of non-generic collections such as .NET's ArrayList, HashTable, etc. I know that using these types of collections for primitive types is a…
easuter
  • 1,167
  • 14
  • 20
2
votes
4 answers

How do I specify a constraint that says "collection of nullable types"?

I'm trying to create a generic argument-validation method that checks collection parameters for null, empty, or contains a null element. public void Foo(ICollection bar) { // Validate parameters ThrowIfNullEmptyOrContainsNull(bar,…
Scott Smith
  • 3,900
  • 2
  • 31
  • 63
2
votes
2 answers

How to convert JsonResult.Data output to original type?

My controller is returning Json result of List Public ActionResult Index([DataSourceRequest] DataSourceRequest request) { var list = new List(); Json(list.ToDataSourceResult(request), JsonRequestBehavior.AllowGet); } Below is…
Pawan
  • 2,150
  • 11
  • 45
  • 73
2
votes
4 answers

Using the generic type 'System.Collections.Generic.List' requires '1' type argument(s)

I have an assignment to create a "Tweeter" app in c#, and for some reason I can't get it to do the most simple thing, add items to a list and display them. I keep getting the error: Using the generic type 'System.Collections.Generic.List' requires…
Austen
  • 283
  • 1
  • 4
  • 16
2
votes
2 answers

Cannot convert type 'T' to 'T'?

I renamed the question from: "Why does my UpCast() not compile as an instance method but does as an extension?" to something a bit more useful for the future emaciated adventurer. I originally set out to implement an UpCast() as an instance method,…
codenheim
  • 20,467
  • 1
  • 59
  • 80
2
votes
1 answer

Casting TList to TList

I have a list of type TList. I need to cast it and use it as TList like this: procedure mainForm.testCast; var listT: TList; listW: TList; obj: TObject; begin listT := TList.create; listT.add(form1); …
iPath ツ
  • 2,468
  • 20
  • 31
2
votes
4 answers

How to convert LINQ query result to list and return generic List?

I used generic ORM list example. This is my table. Person table Guid Name LastName and this is my struct class. public struct PersonItem // database and class field names are the same { public Guid Guid{ get; set; } …
2
votes
4 answers

Add parent object to List - Java

I am trying to put a subclass object into a List but I am unable to do so because of the compiler error mentioned as a comment. Can someone point out what is the correct way to do this in Java? public class Animal { } class Util { private…
BipinK
  • 125
  • 7
2
votes
1 answer

How do I write a C# method to return a Func based in an enum parameter?

I have a set of methods each of which return an ObservableCollection for various types of T, and would like to be able to write a factory method that returns these methods, based on an enum value sent in. For example, suppose I have the following…
Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106
2
votes
3 answers

Which generic collection should i choose in C# to maintain sorted "list"

I have Node class which has a float Distance property. I want a data structure that i can put inside it all my nodes and they will be stored sorted (like in AVL tree or Red Black Tree). I want to insert in O(log(n)) I want to retrieve and remove…
OopsUser
  • 4,642
  • 7
  • 46
  • 71
2
votes
1 answer

C# Linq SelectMany, returning entire object

I have a class like this: public class FileCollection:ObservableCollection. From within the class, I would like to get a subset of the collection, based on a list of names. I imagine it would be something like this: …
Number8
  • 12,322
  • 10
  • 44
  • 69
2
votes
2 answers

C# - how to create an inherited generic collection from a factory method

I am trying to write a factory method that will create a derived instance of an abstract generic collection class. Here are the base classes ... abstract class ItemBase { } abstract class CollectionBase : Collection where T : ItemBase, new()…
Tim Coulter
  • 8,705
  • 11
  • 64
  • 95