Click here to Skip to main content
15,892,643 members
Everything / Collections

Collections

collections

Great Reads

by honey the codewitch
Implementing full list support over custom data structures in .NET
by Sander Rossel
Using Venn diagrams to visualize sets.
by honey the codewitch
Easily implement efficient backtracking capabilities over any enumeration
by Rene Bustos
WCF WebService IN VB.NET Response JSON

Latest Articles

by Gerardo Recinto
In-memory B-Tree sorted dictionary
by Bohdan Stupak
Batching is a nice technique that allows you to handle big amounts of data gracefully. Directory.EnumerateFiles is the API that allows you to organize batch processing for the directory with a large number of files.
by Dev Leader
This article is follow up content to previous articles I've written about iterators and collections, but the benchmark results were NOT what I expected!
by Pavel Bashkardin
Represents a C# generic implementation of the NameValueCollection

All Articles

Sort by Updated

Collections 

19 Mar 2024 by Graeme_Grant
I am not sure what you are trying to do however I'll show you how to handle each item in the ObservableCollection. The Item class needs to implement the INotifyPropertyChanged Interface (System.ComponentModel)[^]. Microsoft provide a sample: How...
17 Mar 2024 by Pete O'Hanlon
You cannot tell if an object has been changed using an ObservableCollection. The way to do this is to use INotifyPropertyChanged and raise the PropertyChanged event whenever you change the value in a property.
17 Mar 2024 by Sh.H.
Hi folks. I have an Observation Collection. I used event CollectionChanged. But this event only raises when new item added, or an item deleted. So how can I detect if an item edited? (And ofcourse, it would better also to detect which item got...
12 Mar 2024 by hardover
With guidance from others, I have solved the problem. The key was to use the PropertyChangedCallBack to manage when the SelectTags List was bound. In summary, the solution involves capturing the point at which the actual List binding takes...
6 Mar 2024 by Graeme_Grant
List is not a bindable collection. You need to use the ObservableCollection Class (System.Collections.ObjectModel) | Microsoft Learn[^]. Here is a working solution for a similar question. Create a new project and add this code: 1. Classes: ...
6 Mar 2024 by hardover
Binding not working when Custom Control is used in a DataGridTemplateColumn My charge is to provide a control that can be used to select multiple items from a list of items. The items are classification tags. The object is a Tag. It has three...
26 Jan 2024 by Gerardo Recinto
In-memory B-Tree sorted dictionary
12 Aug 2023 by Bohdan Stupak
Batching is a nice technique that allows you to handle big amounts of data gracefully. Directory.EnumerateFiles is the API that allows you to organize batch processing for the directory with a large number of files.
19 Jul 2023 by FuFu Dev's
I have a two models (Current and Original) that have the same properties. I want to build in a validation to check if one of the properties (Address - which is a collection consisting of "Country, City, Suburb, Code") have the same values or they...
19 Jul 2023 by PIEBALDconsult
If you have access to the code for the Address class, you can add the ability for them to compare themselves. The following is a very naïve example. Comparing addresses is a very complex topic with many pitfalls. public partial class Address...
3 Apr 2023 by Richard MacCutchan
You need to look at the actual values that are being passed in to the following lines. if not result: result[operation] = [(tuple(unique_value_freq_input), result12)] else: result[operation].append((tuple(unique_value_freq_input),...
3 Apr 2023 by Apoorva 2022
I've written a python code to check the unique values of the specified column names from a pandas dataframe. What I have tried: Main Code: Checking the unique values & the frequency of their occurence def uniq_fun(df, col_name): try: ...
17 Mar 2023 by Dev Leader
This article is follow up content to previous articles I've written about iterators and collections, but the benchmark results were NOT what I expected!
13 Feb 2023 by Grant Mc
Hi. Lets say I have a collection called Orders, and one of the members in the collection, is another collection called Products. So if I have an order, say ID = 001, and it has two different products, I would like to show this on a DataGrid,...
13 Feb 2023 by Grant Mc
OK, still working through this, but here is what I have so far. public partial class MainWindow : Window { MovieCollectionViewModel movieCollection; ObservableCollection actors; public MainWindow() { ...
12 Feb 2023 by Graeme_Grant
This link will show you how: DataGrid with row details - The complete WPF tutorial[^] Here is a little demo with Order > Product grouped data structure: public partial class MainWindow : Window { public MainWindow() { ...
17 Jun 2022 by Member 13102977
String[] stockPrice = { "Reliance", "2022-01-01 10:00", "100", "Reliance", "2022-01-01 10:34", "110", "Tata", "2022-01-01 10:30", "500", "Reliance", "2022-03-02 10:15", "120", "Tata", "2022-01-01 12:00", "400"...
10 Jun 2022 by Richard MacCutchan
You should make it into a multi-dimensional array like: String[][] stockPrice = { { "Reliance", "2022-01-01 10:00", "100" }, { "Reliance", "2022-01-01 10:34", "110" }, { "Tata", "2022-01-01 10:30", "500" }, { "Reliance",...
7 Feb 2022 by Pavel Bashkardin
Represents a C# generic implementation of the NameValueCollection
1 Feb 2022 by Patrick Skelton
In C#, I thought the rule was that any collection with an Add() function could participate in declarative initialisation? I have two such collections that are nested one inside the other. Is there a way to declaratively initialise it, rather than...
31 Jan 2022 by Patrick Skelton
This is perhaps as close as I am going to get: private static Dictionary _dataStructure = new Dictionary { [ "One" ] = new MyDataPlot { { 2, 6 }, { 7, 4 } }, [ "Two" ] = new MyDataPlot { { 5, 16...
31 Jan 2022 by Richard Deeming
A collection initializer can work with multiple parameters - for example: private static Dictionary _dataStructure = new() { ["Foo"] = new MyDataPlot { { 0, 1 }, { 2, 3 }, { 4, 5 }, }, }; ...
31 Jan 2022 by OriginalGriff
Because Add is a void method, you can't use it directly in an initializer. Change it to return the MyDataPlot instance, and it works: public class MyDataPoint { public MyDataPoint(int x, int y) { X = x; Y = y; } public...
14 Jan 2022 by Electro_Attacks
I've written a custom ToolTip Class, that has multiple Settings which were contained in a seperate class called ToolTipInfo. I've managed to make them all Displayed in the Designer and all value changes were saved, except of my Collection...
14 Jan 2022 by Electro_Attacks
Ok guys, I've managed to get my code working, somehow... It's not tested completely, but it looks promising to me :) If you find any errors doing testing, or any suggestions how I can improve my code, let me know... You might need to comment...
15 Dec 2021 by Member 15463307
Hi, how can I make Locale output that the language of the passport is Russian, and for each element in the array list, to call the method isRussian(); public class Passport implements Comparable{ private String firstName; ���...
15 Dec 2021 by Richard MacCutchan
See Locale (Java Platform SE 8 )[^]
15 Dec 2021 by Member 15462808
Hello, How can i create a new array list "onlyRF", and here to print only the books with genre Romance and Fiction, from the array list "books"? List books = new ArrayList(); //from this i have to print in new one, only the book...
15 Dec 2021 by Richard MacCutchan
List onlyRF = new ArrayList(); // this is the one where only the Romance and Fiction book will be for (Book b:books) { // if Romance or Fiction, add to onlyRF list if(b.getBookGenre().equals(LiteratureGenre.Romance) ||...
23 Nov 2021 by honey the codewitch
Easily compare collections for equality
3 Nov 2021 by Vishal Ekkaldevi
I have a requirement where a map contains values which were the keys of other maps. Like below example Map keysMap = new HashMap(); one.put("Car","4 Wheeler"); one.put("Bike","2 Wheeler"); Map m1 =new...
31 Aug 2021 by Flidrip
My DataGrid is bound to an ObservableCollection in my ViewModel. I add new rows via a command that looks like this: public void AddItem() { MyObservableCollection.Add(new MyClass()); } How can I set default value for a...
31 Aug 2021 by Richard Deeming
Set the properties on the new instance of your class to the appropriate default values: MyObservableCollection.Add(new MyClass { PropertyName1 = "Default value for property 1", ... });
23 Mar 2021 by honey the codewitch
Make your code more efficient by hacking your compiler to improve its optimization capabilities
28 Jul 2020 by rtybase
There is one ambiguous moment in the Java documentation of the compute() method from the ConcurrentHashMap class.
24 Jun 2020 by Dave Kreskowiak
Couldn't tell you what you're missing. There's nothing that stands out as wrong with the code you posted. EF is writing 125 records because your code is giving it 125 objects to write. You're going to have to step through the code,...
24 Jun 2020 by Tshumore
I have a utility that reads the status of MicrosoftBizTalk Server resources .. specifically the ReceiveLocation component. My problem is that the program is submitting multiple entries of each item i.e each item in the data returned is being...
5 May 2020 by honey the codewitch
This tip shows you a robust way to get the type of items a collection can hold. It works with non-generic collections too.
26 Apr 2020 by OriginalGriff
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here... A very quick search using your subject as the search term gave over 2 million hits: implement a hash table using only...
24 Feb 2020 by honey the codewitch
A relatively safe, simple, yet high performance technique for using lists as dictionary keys.
9 Feb 2020 by honey the codewitch
Using IEqualityComparer to allow collections to be keys in dictionaries and hashsets
6 Feb 2020 by honey the codewitch
A circular buffer implementing IList
23 Dec 2019 by honey the codewitch
Easily implement efficient backtracking capabilities over any enumeration
5 Dec 2019 by honey the codewitch
Fills a gap in Microsoft's Queue offering with an alternative allowing efficient indexed access
20 Nov 2019 by honey the codewitch
A fully generic ordered dictionary class in C#
17 Nov 2019 by honey the codewitch
Implementing full list support over custom data structures in .NET
13 Sep 2019 by honey the codewitch
A B-tree, an AVL tree, and a Splay tree in C#
17 Jul 2019 by ireland94
This program demonstrates the methodology needed for by directional messaging between a Java FX foreground and 1 or more background threads.
10 Jun 2019 by Member 14492636
Given an integer array of size N. For each element in the array, check whether there exist a smaller element on the next immediate position of the array. If such an element exists, print that element. If there is no smaller element on the immediate next to the element then print -1. What I have...
10 Jun 2019 by CPallini
Try: import java.util.*; import java.lang.*; import java.io.*; class GFG { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); List list = new ArrayList(); while(t-- > 0) { list.add(sc.nextInt()); ...
12 May 2019 by Member 12087373
I need to save those six fields in same column but not in same row and same cell. each field have default GUID.so i decided to put that default guid's in one list and fields in one list and call that object of that particular list where we want .ArrayList Alist = new ArrayList(); ...
21 Feb 2019 by Ralf Meier
I modified your (for me relevant) Code a little bit to make it work. I think that will help you : Imports System.Windows.Forms.Design Imports System.ComponentModel Public Class CustomerComponent Inherits Component ...
21 Feb 2019 by Gdno
Hello, Im creating a component that I call CustomerComponent, this component has only one property called Customers that receives a collection from my Customer class. Im trying to create a Form to edit this collection at design time through UITypeEditor. However, the values ​​added at design...
19 Feb 2019 by Member 13974276
Everything was fine. I had to use AddRange() instead of Concat() obj.AddRange(ob);
19 Feb 2019 by Member 13974276
I have created an object of type List and I am concatinating another collection of type IEnumerable into it but the the object always showed zero record while debugging. When I debugged, the Count for obj was zero obj = 0 Where have I gone wrong? Or is there another way to do it? I even tried...
19 Feb 2019 by OriginalGriff
Assuming you can get that to compile - it won't as shown - start with the debugger: put a breakpoint on the line var obj = new List(); and look at the content of param to find out how many objects it contains. At a guess, none. No objects, no foreach body execution, no objects added...
8 Jan 2019 by Simmerliner
I've defined a class like this: class TextEnhancement ... public TextEnhancement(int offset, int length) { ... } And then I've defined a collection that uses this type as: public List mTextEnhancements; Normally I'd then add an element to this collection thus:...
8 Jan 2019 by Simmerliner
Excellent! Thanks David. That makes total sense.
8 Jan 2019 by Dave Kreskowiak
Create your own collection type, inheriting from Collection: public class TextEnhancementCollection { public void Add(int offset, int length) { Add(new TextEnhancement(offset, length); } } Create your collection instead of using List: ...
30 Dec 2018 by Bryian Tan
Not clear how the selectedIDs is being generated. I think the following save(['']) should work if selectedIDs = '1','2','3' A quick work around, in the save function, use the split() function to split the selectedIDs into array object String.prototype.split() | MDN[^]
30 Dec 2018 by Member 13974276
I am selecting some checkboxes and then sending the ID of those checkboxes to a button in a HTML page After selecting the checkboxes the IDs are stored in an object selectedIDs. This object is passed to the button. When I debugged and checked, the object received the IDs as I want i.e....
26 Dec 2018 by Jatinath
List> totals = new List>() { new KeyValuePair("Key1", 10), new KeyValuePair("Key2", 15), new KeyValuePair("Key3",...
26 Dec 2018 by Jatinath
Hi, just update below code. cheking for non zero value here. [from line num 18 in previouse code] List> totals = new List>() { new KeyValuePair("Key1", 10), ...
26 Dec 2018 by TheBigBearNow
I have a multidimensional array with basically a key / value pair. I would like to sum all the values according to the key then pick the min and max values from this. I tried making a List and a dictionary to do this I got very close but it wouldn’t let me sort through a list of...
27 Sep 2018 by Gdno
Please see if this helps you in some way, see that in the "TargetControls" property of the control that is in form1 you can select the controls of the same type, to appear all the controls is just to change the control code, where is ExampleControl you changes to Control. Link to demo:...
27 Sep 2018 by teolazza
I, I've created a component with a collection of controls as property:[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public List ControlsToNotTranslateThen I've created an UserControl, added some controls to it: buttons and labels.Now I...
12 Jul 2018 by Gerry Schmitz
Effective wooden board cutting algorithm - Stack Overflow[^]
12 Jul 2018 by theskiguy
I have a list of double that contains percentages (numbers from 0 to 1). These numbers equate to the percentage of a parent piece of material required to make part. I am trying to get the total material required but I can’t just add all these numbers up because it doesn’t account for any...
9 Jul 2018 by User 8406082
Issue: The `VisualListViewItem` text draws in the first `VisualListViewSubItem` text position also when using the designer. ---------- Image: [Design](https://i.stack.imgur.com/st9z1.jpg) [Debug](https://i.stack.imgur.com/gBHka.jpg) ---------- Steps to reproduce: 1. Add `VisuaListViewEx`...
6 Jul 2018 by vudangngoc
Travelling over Java collections is just a piece of cake, but when the size of the collections increases you have to choose wisely
25 Jun 2018 by David Serrano Martínez
A lazy stream has been implemented in C++11, so as to highlight the functional capabilities of this new specification
3 May 2018 by four systems
Hello, The code for buffered reader that reads numbers from file and sorts them is: package inout; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class...
24 Feb 2018 by BillWoodruff
If you are serious about understanding time performance in .NET, I suggest you learn to use one of these open-source tools: BenchmarkDotNet (what I use) [^], or, AppMetrics [^]. By doing this, you will become a better programmer. Scott Hanselman wrote about BenchMark in 2016: [^]. Both these...
24 Feb 2018 by Akhil Jain
This is my code in which a list contains 2 more lists where the WorkItem collection contains a large number of records such as 7,000 it takes 10 min. Is there any way to make it faster and in case it's deciding the workItem type if it's a bug, task or product backlog item. Please tell me how to...
24 Feb 2018 by Patrice T
I see nothing obvious. You need to understand where and how time is spent, the tool of choice is a profiler. Profiling (computer programming) - Wikipedia[^] List of performance analysis tools - Wikipedia[^] [Update] Quote: have put stopwatch before and after the loop and it show's 10 min ...
12 Feb 2018 by arunlakra15
Is there any way, we could view complete definition for CollectionBase class in System.Collection namespace ? Even in msdn, I couldn't find the method definitions in CollectionBase class. Although, the web pages in msdn contains only the properties and method declarations, the definitions are...
12 Feb 2018 by Member 13674833
THE COLLECTIONBASE CLASS The .NET Framework library does not include a generic Collection class for storing data, but there is an abstract class you can use to build your own Collection class—CollectionBase. The CollectionBase class provides the programmer with the ability to implement a custom...
7 Jan 2018 by Maciej Los
I'm not sure i understand you correctly, but... If you want to get list of tables and their columns with information about primary keys, you have to change your PrimaryKeysObj this way: public class PrimaryKeyObj { private string schema = string.Empty; private string sPK = string.Empty; ...
7 Jan 2018 by User98743
My application iterates through the tables in my database. For each table that has a Primary Key, it needs to know the Primary Key columns. I'm using OleDb's GetOleDbSchemaTable, which returns a DataTable like this: Primay_Key_Name, Table_Name, Column_Name, Ordinal PK_ZipCode, Cities, ...
4 Jan 2018 by john morrison leon
Class method emulation for plain arrays plus unified handling of plain arrays, std::arrays and std::vectors
21 Dec 2017 by rtybase
An use case for ConcurrentHashMap
13 Oct 2017 by Maciej Los
There's no need to use .StartWith or .Contains method. Simple .Replace should be enough :) var result = config.Select(x=>x.Replace("userdata.", string.Empty)).ToList(); Of course, if you want to return only data with member word, you can use: var result =...
13 Oct 2017 by Member 10281805
Hi, I want to filter string list based on some condition as given below, List config = new List(); config.Add("userdata.member1"); config.Add("userdata.member2"); config.Add("userdata.member3"); ...
13 Oct 2017 by Karthik_Mahalingam
try string[] userDataKeys = config.Where(x => x.Contains("userdata.")).Select(x => x.Replace("userdata.", "") ).ToArray();
13 Oct 2017 by Pete O'Hanlon
You're almost there. First you need to identify which records contain userdata.. A where clause helps here:config.Where(x => x.StartsWith("userdata.")).Select(x => x.Replace("userdata.", string.Empty)).ToList();
21 Sep 2017 by Richard Deeming
You don't need to map the member; you just need to map both types. Given: namespace Db { public class Order { public List Ship { get; set; } } public class ShipOnly { public string Name { get; set; } } } namespace Dto { public...
21 Sep 2017 by Member 13229879
I want to map list of Dto to other object to using Automapper Source: public class Order { public List Ship { get; set; } } public class ShipOnly { public string Name { get; set; } } Destination public class Order { public...
1 Sep 2017 by Member 13389077
How can i get a different numbers of images from collectionCell into scrollView with use firebase? In my project i have three viewController's. FirstVC - collectionView inside a tableView. CollectionView need for display the main images for scroll their. TableView need for display the name and...
16 May 2017 by Rene Bustos
WCF WebService IN VB.NET Response JSON
14 May 2017 by Sander Rossel
Creating a lightweight JavaScript library that brings proper .NET-like collections and LINQ to JavaScript.
26 Mar 2017 by Aydin Homay
In this article, I tried to show a real benchmark based on presser test method, for a Big Data collection deals on C++, C#, and VB.NET.
16 Mar 2017 by Rockstar_
Hi All,I've added an email address in both TO and CC fields(same email in both textboxes). The recipient is getting two emails.My tester is expecting only one mail, I tried removing the duplicate email from CC field. But my tester is expecting when he opens the ibox and see the TO and...
16 Mar 2017 by Jochen Arndt
Your tester does not know what he talks about. If you specify the same address multiple times, it will be send multiple times. It does not care in which of the destination fields ("To", "Cc", "Bcc") the address is specified. The SMTP server will parse all fields and forward the message to each...
23 Oct 2016 by NotPolitcallyCorrect
Date is a reserved keyword. You will need to use something else.
20 Oct 2016 by Luiey Ichigo
Hi,How to make the generated code in Azure Machine Learning works on VB.NET?I'm stuck on part of defining scorerequest variable value.Original code from C#:public class StringTable{ public string[] ColumnNames { get; set; } public string[,] Values { get; set; }}class...
20 Oct 2016 by kjburns1980
I have written a publisher-subscriber system for a multi-threaded project I am working on. It is my understanding that when using SynchronizedList structural operations are supposed to be thread-safe, but iteration requires that the list be wrapped in a synchronized block.For these reasons,...
11 Oct 2016 by w1sph
Hi All,I am trying to figure out how to add a new 'row' in a collection in MVC4My model contains a IList.This list is looped, for every record a EditorFor is called.Everything works fine (including posting back), except adding a new record.I would like to collect the html of a...
11 Oct 2016 by w1sph
Yuk..dirty fix:Send a counter with the Editor ViewData, use this to manualy construct the name and id of the controls.in the Ajax call I send the HtmlTable tr count to the PartialView request. @Html.EditorFor(m => Model.Regels_[i], new { count = i...
2 Oct 2016 by Gold$Coin
I am having Application slowness when i suppose to get distinct out a DataTable which has 50k+ records. i am using the below code to do it/// /// Generate Distinct Data Table from the Data Table Generated from server. /// Func