generic-list Questions

5

Solved

I've spent some time looking for some alternative to handle generic objects, I've seen questions similar to mine, but not as specific I suppose? Protocol buffers has multiple scalar types that I ca...
Subsoil asked 6/9, 2012 at 17:27

6

Solved

In C#, if I have a List<T>, and I have an object of type T, how can I replace a specific item in the List<T> with the object of type T? Here is what I have tried: List<CustomListItem...
Brendabrendan asked 5/11, 2014 at 8:49

8

Solved

what is fastest way to remove duplicate values from a list. Assume List<long> longs = new List<long> { 1, 2, 3, 4, 3, 2, 5 }; So I am interesting in use lambda to remove duplicate and r...
Staysail asked 17/5, 2012 at 9:12

32

Solved

What is the best way to randomize the order of a generic list in C#? I've got a finite set of 75 numbers in a list I would like to assign a random order to, in order to draw them for a lottery type...
Sylvestersylvia asked 7/11, 2008 at 19:28

7

Solved

OK so I'm fairly new to unit testing and everything is going well until now. I'm simplifying my problem here, but basically I have the following: [Test] public void ListTest() { var expected = ne...
Greene asked 8/11, 2013 at 14:36

3

Solved

How do I convert the following Enum to a List of strings? [Flags] public enum DataSourceTypes { None = 0, Grid = 1, ExcelFile = 2, ODBC = 4 }; I couldn't find this exact question, this Enum to...
Lekishalela asked 20/2, 2013 at 3:9

4

Solved

I am trying to find the right way to use a Generic List of Generic Interfaces as a variable. Here is an example. It is probably not the best, but hopefully you will get the point: public interfac...
Spectroradiometer asked 23/12, 2010 at 21:23

2

I am trying to make a list of all items in the game using System.Text.Json; I am very new to using .json files I have tried doing this to test if it works: List<Item> AllItems = new List&lt...
Stevenson asked 6/7, 2021 at 17:33

2

Solved

I have a need/want to return a [System.Collections.Generic.List[string]] from a function, but it is being covered into a System.Object[] I have this function TestReturn { $returnList = New-Object ...
Cygnet asked 20/5, 2021 at 19:31

10

Solved

I have a class containing several properties (all are strings if it makes any difference). I also have a list, which contains many different instances of the class. While creating some unit tests ...
Colporteur asked 27/3, 2012 at 15:48

3

Solved

I have read many posts on this topic; among them and most recently .NET - Convert Generic Collection to Data Table. Unfortunately, all to no avail. I have a generic collection of structures : Pri...
Kingdon asked 26/11, 2009 at 21:4

6

I have a very large list of integers (about 2 billion elements) and a list with indices (couple thousand elements) at which I need to remove elements from the first list. My current approach is to ...
Palla asked 19/8, 2020 at 21:29

11

Solved

I have a class Items with properties (Id, Name, Code, Price). The List of Items is populated with duplicated items. For ex.: 1 Item1 IT00001 $100 2 Item2 IT00002 $200 3 Item3 IT00003 $150 1 It...
Fredenburg asked 22/10, 2009 at 11:48

5

Solved

I want to add a "Select One" option to a drop down list bound to a List<T>. Once I query for the List<T>, how do I add my initial Item, not part of the data source, as the FIRST eleme...
Pandemic asked 24/12, 2008 at 0:34

7

I want my program to read from two text files into one List<T>. The List<T> is sorting and cleaning duplicates. I want the List<T> to save (after sorting and cleaning) to a txt f...
Spread asked 16/1, 2012 at 17:1

5

Solved

How can one convert a list of objects to a queue thereby maintaining the same order?
Delrio asked 11/8, 2010 at 23:37

1

I'm looking at the open source code for System.Collections.Generic.List<T>. The AddRange(IEnumerable<T>) method looks like this: public void AddRange(IEnumerable<T> collection) { ...
Down asked 22/2, 2019 at 20:18

2

Solved

I'm trying to pass the list of my class as DbParameter. Probably the table type is defined in my stored procedure. Now, I'm not getting how to pass the List<> into the stored procedure as t...
Horal asked 5/6, 2014 at 13:38

3

Solved

Let's say I have an object that represents a field of data, that object needs the following properties: Name, Type, Value, Length. Here is the object: class Field<T> { public string Name { ...
Margaretemargaretha asked 21/10, 2013 at 9:32

4

Solved

See the code sample below. I need the ArrayList to be a generic List. I don't want to use foreach. ArrayList arrayList = GetArrayListOfInts(); List<int> intList = new List<int>(); /...
Madiemadigan asked 24/4, 2009 at 15:10

5

How do I edit an item in the list in the code below: List<Class1> list = new List<Class1>(); int count = 0 , index = -1; foreach (Class1 s in list) { if (s.Number == textBox6.Text) ...
Parlando asked 6/2, 2011 at 17:9

4

Solved

I have a generic list that is being used inside a method that's being called 4 times. This method writes a table in a PDF with the values of this generic list. My problem is that I need to reverse...
Mother asked 30/9, 2013 at 19:16

1

Solved

I've already checked a few other posts regarding reflection and overloaded methods but could find any help. One post I found was this one, but that didn't help a lot. I have the following two meth...
Longish asked 15/6, 2017 at 13:35

4

Solved

I have a number of objects defined, each has a property named "CreateDate". Is it possible to write a single, generic method to select the highest date from an object that I specify? I was attemp...
Twicetold asked 5/11, 2012 at 20:57

5

Solved

Does anyone know why the following code does not compile? Neither add() nor addAll() works as expected. Removing the "? extends" part makes everything work, but then I would not be able to add subc...
Percale asked 23/3, 2011 at 15:52

© 2022 - 2024 — McMap. All rights reserved.