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
1
vote
4 answers

Generic Interface

I am designing an app where similar entities are in two places with different types of collection as following. Model: class PersonModel { public string Name { get;set;} public List
Addresses { get;} public List OtherTypes…
hungryMind
  • 6,931
  • 4
  • 29
  • 45
1
vote
1 answer

Duplicating an object in List

Time for my first question! I want to make it known that I'm quite amateur with programming, and I probably don't fully understand the terms I'm about to use. I'm making a program that takes the results from an Oracle Query and displays them in a…
Logarr
  • 2,120
  • 1
  • 17
  • 29
1
vote
5 answers

C#: finding class fields in a List

I have the following code: class exampleClass { int var1; int var2; string var3 } List myList = new List() myList.Add(new exampleClass { var1 = 10, var2 = 100, var3 = "a"}); myList.Add(new exampleClass {…
Nicholas N
  • 205
  • 1
  • 4
  • 8
1
vote
6 answers

C# foreach on a collection of an interface

I'm wondering if there is any functionality built in to C#/LINQ to simplify the following: foreach(var item in collection) { if (item.GetType() == typeof(Type1) DoType1(item as Type1); else if (item.GetType() == typeof(Type2)) …
Jason Fry
  • 1,204
  • 12
  • 24
1
vote
3 answers

Specific generic type of lists within a list

I have a list of lists. I would like to know how I can restrict the generic types of each of the inner lists so each element of the outer list contains an inner list that can only contain one type of object. So far I have tried…
Sujen
  • 1,614
  • 5
  • 19
  • 25
1
vote
2 answers

C# multiple generic types in method input and output collection

I have generic query method which looks like below List Query(QueryModel query) where T : BaseClass { // get data and Deserialize by T } // where T is Table DTO, to Deserialize response by T Now I want to implement multiple query…
Maulik
  • 510
  • 1
  • 7
  • 22
1
vote
2 answers

Adding Data in List inside a Dictionary in C#

In Step 1 I wrote this code to access pre-existing list & add value in it . In Step 2 I updated the dictionary with new list. In Step 3 again I have to access the list inside dictionary to print the result. Is there any process or shortcut to add…
1
vote
3 answers

Adding sorted data into a hashtable or Dictionary while reading the data from file

I have a file with contains as A,15 B,67 C,45 D,10 I am reading the data from file, but i wanted to read the data into a dictionary or hashtable but the data sould be sorted into it by its value that is B,67 C,45 A,15 D.10 If Any other List will…
usr021986
  • 3,421
  • 14
  • 53
  • 64
1
vote
1 answer

Creating json object with duplicate keys in C#

I am creating a json string by serializing an object in C# (using Newtonsoft) to pass to a third party charting library, so have no control over the structure I need to create. The structure requires an object with duplicate keys, something like; {…
Nick
  • 141
  • 1
  • 7
1
vote
1 answer

How can a List references to an ArrayList which has BigInteger values

This method is defined in a JpaRepository and runs a native PostgreSQL query. List distributorIds = distributorRepository .findDistributorIdsWithChildren(distributorId) It runs with no exception and on runtime I see BigInteger values in…
Ismail Yavuz
  • 6,727
  • 6
  • 29
  • 50
1
vote
2 answers

Why does generic TArray Create syntax differs from other class functions?

I've noticed something that appears to me as an inconsistency in the generic TArray syntax (and drives me crazy...) The "constructor" function requires to be called by specifying the type before the function name. MyArray :=…
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
1
vote
1 answer

Adding non class functions to generic TArray class

In System.Generics.Collections, the TArray type has class functions only. For example: class procedure Sort(var Values: array of T); overload; static; This implies the only accepted syntax is the following: var Arr : TArray; begin …
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
1
vote
1 answer

Using TArray class functions

I need to sort a TArray, I've added System.Generics.Collections to the uses clause and then I've tried the following code: var Arr : TArray; begin SetLength(Arr, 2); Arr[0] := 5; Arr[1] := 3; TArray.Sort(Arr); …
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
1
vote
4 answers

C# Generics - cannot convert 'byte[]' to 'T'

I need your help with using generic class and methods in C#. When I call EnqueObject method in ProduceData, on the line with EnqueueObject(block), an error occurs: cannot convert 'byte[]' to 'T'. I would appreciate any advice. (I've simplified my…
1
vote
3 answers

Why is my Collection working differently to my List class when copying?

I want to copy a collection and add new elements to only one of them (not both). In the code example below I copy the collection by creating a new one and passing it in the constructor. After that I add an element in only one of the collections.…
Patrick Leijser
  • 210
  • 4
  • 11