Click here to Skip to main content
15,892,768 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 

20 Feb 2010 by #realJSOP
If you're relying on FXCop to validate your code, you're in for a big let-down. It's only there to provide guidelines that you can choose to follow or ignore, depending on your own code. If you wanted to avoid the warning, you could always retrieve the list outside your Linq statement, and...
22 May 2010 by #realJSOP
In WPF/Silverlight, you might want to bind to a dictionary. Here's a couple of websites I found.
22 Sep 2014 by _groo_
An interface not present in .NET BCL, IIndexable exposes methods for iterating and indexing a read-only collection.
1 Aug 2011 by Abhinav S
Nothing, as far as your example is concerned.In the first case, you could actually define the array count in the first statement but add values to it later.E.g.List withParentheses = new List[4];withParentheses[0]=1;withParentheses[1]=2;In the second case, you don't have that...
1 Jul 2015 by Abhinav S
If you need thread safety, use ConcurrentQueue - ConcurrentQueue[^]. The advantage with this queue is when multiple threads read or write data, locking is taken care of by the queue itself.You could always implement locking in a normal queue.
3 Apr 2013 by Abhinav_Sharma
Actually I want to populate dataGrid with Xml data present in xmlfile and want to add/remove/update the data in the Datagrid. I tried using XmlDataprovider which works fine in populating the dataGrid but I can't manipulate(add/remove/update)the data. Hence ObservableCollection was a...
24 Jul 2015 by Adrian Andrei
Sorry, when I search in google etc. i can't find what i neededI can't keep a collection with items, when I exit the designer or debug, my Collection get blank..Here is my code:ExplorerBarItemData.vbPublic Class ExplorerBarItemData#Region "Fields" Private fText As String =...
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...
29 Sep 2011 by Al Moje
Hi,In your DAL I thing you should do it this way to return theList of User Public Shared Function SelectAll() As List(Of User) 'Create List Of User Dim userColl As New List(Of User) Try 'select * from User _sqlConn = New...
14 Sep 2015 by Andy Lanng
First, I'd suggest looking at csv parsers (just swap the comma for the semi-colon). Dealing with strings inside csv strings is a problem that has been looked into in detail under the guise of CSV Parsing:this one looks good and lists the Quote character as something it deals with:A Fast...
9 Oct 2014 by AnoopGharu
Hello everybody, I am work on the asp.net Profile and currently I am trying to work on the multiple properties to showing in the form page using table's but when I run the application then it shows the this following error:Using the generic type 'System.Collections.Generic.List' requires...
17 Jan 2015 by antobaro
How set values in observable collection ?I have this code:private ObservableCollection _OpenWorkspaces;public ObservableCollection OpenWorkspaces { get { return _OpenWorkspaces; } set { _OpenWorkspaces = value; }}How Can I set the values ? (like this...
30 May 2011 by apaka
Is anybody aware of generic tree for c# that has all of net4 goodies and is stable,fast snd tested. or some for java (maybe I could port it).(probably I'll just get use a google sanswer , but ...) Thanks in advance.
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: ...
26 Apr 2016 by Arthur Minduca
How to choose the right data structure for a collection of elements
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...
11 Oct 2013 by ASP.NET Community
A ValidationSummary control is displayed when the IsValid property of the page is false. It "polls" each of the validation controls on the page and
11 Oct 2013 by ASP.NET Community
The PlaceHolder control can be used as a container control within a document to dynamically load other controls. The PlaceHolder control has no
11 Oct 2013 by ASP.NET Community
The Table class allows you to build an HTML table and specify its characteristics. A table can be built at design time with static content, but the
11 Oct 2013 by ASP.NET Community
Getting started with MongoDBMongoDB is a famous representative of NoSQL databases. It is a document-oriented database, which means that data will
11 Oct 2013 by ASP.NET Community
Few days back I came across a problem on asp.net site wherein a user wanted to get information about controls of a Page from a different page.
11 Oct 2013 by ASP.NET Community
ASP.net offers a built-in functionality for tracing theapplication. Using this functionality one can view a lot ofdiagnostic
13 Oct 2013 by ASP.NET Community
When you Try this on Asp.net 2.0 WebSite:http://www.YouWebsite/default.aspx?__VIEWSTATE=COUCOU!You will have something like that:Server Error in '/'
25 Nov 2009 by AspDotNetDev
You are setting isRunning to true after the first iteration. Since the if statement inside your for loop checks isRunning, it will skip over all but the first item in the for loop.When you say timer.Start(), the greenCount() method will never actually be reached until the timer() method has comple
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.
18 Aug 2010 by B. Verboven
Convert a generic list of (recursive) objects into a simple hierarchical TreeList
18 Mar 2012 by B. Verboven
This is an alternative for "A simple generic TreeList".
4 Sep 2012 by BeStelios
Hi, I have created an ICollectionView:private ObervableCollection MyCollection = new ObervableCollection();public ICollectionView View {get; private set; }private void Init(){ CollectionViewSource Cvs = new CollectionViewSource(); Cvs.Source =...
4 Sep 2012 by BeStelios
public class ViewModel { ObservableCollection CustomerList = new ObservableCollection(); public ICollectionView BlueCustomersView { get; private set; } public ICollectionView BlackCustomersView { get; private set; } public ICollectionView...
17 Jan 2015 by BillWoodruff
using System.Collections.ObjectModel;namespace TestObservableCollection{ public class WorkSpace { public int ID { set; get; } public string Name { set; get; } public WorkSpace(int id, string name) { ID = id; Name =...
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...
13 Jun 2011 by BobJanova
The collection should be within the parent object when that tree relationship makes sense – i.e., if a fruit is associated with exactly one person. For any individual item of fruit that may be the case, but for fruit types, it is not. So I would go for something likeclass Person {...
25 Jul 2011 by BobJanova
To fully support data binding the collection should implement IBindingList (i.e. BindingList) or INotifyCollectionChanged (e.g. ObservableCollection). You can use a BindingSource but you still have to make sure that it is notified of changes if the underlying collection doesn't do that...
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.
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[^]
12 Apr 2011 by CalicoSkies
How to use istream_iterator and the copy algorithm to populate an STL collection from a text file with very little code
30 Dec 2014 by chandra sekhar
I have a list like IList backplanes = panel.Items.Where(x => x is BackPlanes).OrderBy(x => x.Index).Cast().ToList(); backplanes = backplanes - 1;I am getting an error like Operator - cannot be applied to operands of type...
27 Jan 2015 by chandra sekhar
I have a list like AncillariesList = new ObservableCollection();and it contains a value named Lineno.So if the list contains some 20 values and the last value is 1200, i want to increment from the last value when the user click on add button.How can i achieve this??
18 Feb 2015 by CHill60
An alternative approach (I'm not suggesting it's the best one!)You could have a Dictionary of , string>. For example, using your data which I've deliberately changed the order on, and just using string for the object for now var original = new...
8 Jun 2010 by Chris Trelawny-Ross
There is no need to remove and re-add the inner dictionary when removing an item from it, so you can just do:// To remove outer[1][2]outer[1].Remove(2);
25 Nov 2009 by Christian Graus
timer.Interval = TimeSpan.FromMilliseconds(1); This is insane.  You think you can see one millisecond ? 30 milliseconds is WAY too short.  And why have a timer if you're going to use a counter inside it ? Why not set the timer to 500 milliseconds and just swap every time ?
19 Nov 2013 by cigwork
Getting "random" crashes in application, _probably_ due to threading issues. One of our favourite search engines turns up : Found SO Q.[^] Which has similarities, but a blanket swap of collections, as suggested in the SO response, isn't an option in the case I'm dealing with. I'd be...
25 Oct 2012 by cjb110
I've got the following setup:class A{ ObservableCollection Bs {get;set;}}class B{ string Title {get; set;} ObservableCollection Cs {get;set;}}class C{ string Title {get;set;}}I'm trying to get a list of unique Title's in the entire of A.So far...
20 Aug 2012 by Clifford Nelson
You have two ways to associate Employees and Departments using objects. One is to have a Department property in the Employee object and the other is to have a collection of Employee objects in the Department object. You will also, at the minimum have either a collection of all Department or all...
26 Sep 2012 by Clifford Nelson
I have used the Dispatcher, and it does not seem to be very reliable. Had much more luck with tasks: First get a TaskScheduler from somewhere that is on the UI thread:TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();Then in the place you need to make changes...
22 Feb 2011 by cp.soni
Plese see following link, http://blogs.msdn.com/b/vinsibal/archive/2008/05/20/wpf-3-5-sp1-feature-ieditablecollectionview.aspx[^]This may help in giving some hint. Not sure if you have already gone thru with that.Edit : Provided the correct link.
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()); ...
26 Sep 2012 by cpquest
Hi all,i have implemented a Extension method for ICollection f in project that bacically i am trying to do some datagrid related operation on ApplicationIdle state. here is the code. public static class CollectionExtension { /// /// Set item Binding to...
16 Aug 2011 by Damian Flynn
Here's a couple of gems...From IList to DataTable.From DataTable to array of T.// DataTable: from IListpublic static DataTable ToDataTable(this IList iList){ DataTable dataTable = new DataTable(); PropertyDescriptorCollection propertyDescriptorCollection = ...
29 Dec 2009 by dan!sh
I would be better if you post the question under the forum below the article itself. That way the article writer will be notified and will help you out.
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: ...
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,...
15 May 2010 by DaveAuld
See this article;NeroBar[^]
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
7 Jan 2016 by debashishPaul
You are trying to convert the ArrayList to Guid.TaxFieldID = new Guid(Alist .ToString ())Use an iterator (for / while / foreach) to iterate through the ArrayList items and convert each item.
26 Dec 2013 by Dev Leader
In this article, I’d like to go over a couple of different approaches for an API and then explain why the yield keyword might be something you consider next time around.
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!
10 Mar 2014 by Dineshkumar Ramakrishnan
Hi ,I want to create a Menu Control in asp.net, which is placed in the left pane of my UI Screen.I need this menu control with Collapsible and Expand Menu feature, That is,Main Menu-1 Sub Menu-1 Sub Menu-2Main Menu-2 Sub Menu-1 Sub Menu-2 From Above Shown...
17 Mar 2012 by dkgawriya21
string[] strArray = new string[5];strArray[0] = @"C:\MyFolder\Software";strArray[1] = @"C:\MyFolder\Admin";strArray[2] = @"C:\MyFolder\Accounts";strArray[3] = @"C:\MyFolder\HR";strArray[4] = @"C:\MyFolder\Maintainece";foreach (string node in strArray){ string[] strpart...
7 Sep 2016 by DRD94
What I have attempted to do is filter an ObservableCollection of Companies as the user is typing into a TextBox. The user is able to check CheckBoxes to add further criteria to what they would like to search on. Sorry if this is a particularly long example but as I said, the method is very...
25 Nov 2009 by Eightbitz
Having trouble iterating through a stack for a "Simon" game. I created a random string generator to populate a stack to iterate through to trigger timers, and I can only get it to iterate the same index over and over. How do I get it to return to timer() and go to the next item in the stack (mySimon
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...
14 Jul 2011 by eranotz50
my assignment is to create a DBMS iv'e created 3 classes witch build an hierarchy similar to the DataTable and DataRow ClassesEntity (T)-> Table -> Record -> Fieldthe Table is created from an Entity using Reflectionwhy and how i created them is not the issue .what i need now is to index...
20 Jan 2012 by Erik Rude
I've got the following two combo boxes. One updates the content when the SortedList changes and the other doesn't.
22 Jan 2012 by Erik Rude
Thanks to SteveAdey for pointing out the fatal flaw.In the end I bound to the SortedList changed the SelectedValuePath and used a DataTemplate binding to the Value to get to my desired goal.My solution looks like this:
7 Jan 2014 by Erik Rude
Since it seems you like LINQ - here's a good start. look at the group by examples:http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b[^]
30 May 2011 by Espen Harlinn
Just a followup on SAKryukovs' answer, how about:public class TreeNode{ public class ChildList : BindingList > {} private ChildList children; private T data; public TreeNode() { children = new ChildList(); } public TreeNode(T...
10 Jun 2015 by F-ES Sitecore
public class Person{ public int ID { get; set; } public string Name { get; set; }}DataTable dt = new DataTable();dt.Columns.Add("ID", typeof(int));dt.Columns.Add("Name", typeof(string));dt.Rows.Add(1, "John");dt.Rows.Add(2, "Dave");List people =...
17 Oct 2012 by fjdiewornncalwe
We're not going to do your homework for you, but I will give you some pointers.1) You'll need a collection object to put the words into as you read them.2) Before you actually insert a found word into the collection, you'll need to make sure that the word doesn't already exist in the...
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...
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...
20 Feb 2012 by Fredrik Bornander
Deferred execution is the culprit here (I think), the sort isn't run until the result is enumerated so when you do this;orderedList.Contains(923456); you're resorting the list again for every iteration. ToList forces the result to be enumerated up front.You can see this by changing...
27 Sep 2013 by Fredrik Bornander
Unless the callers need to change the result set then I'd recommend returning a IEnumerable of Students instead.public static IEnumerable Show() { using (var DB = new UniversityDataContext()) { return DB.SPShow(); // Might want to ToList here to prevent deferred...
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...
14 Sep 2015 by ganeshbdas
try this solution string value ="France;Japan;Russia;China;\"India;New-Delhi\";\"NewZeland;Wellington\";England'"; string ReplaceDoubleQuote = value.Replace("\"", " "); string[] words = ReplaceDoubleQuote.Split(';');
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:...
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...
28 Feb 2011 by George Tryfonas
An ObservableCollection wrapper for an array which notifies the observer about changes to its underlying array
26 Jan 2024 by Gerardo Recinto
In-memory B-Tree sorted dictionary
12 Jul 2018 by Gerry Schmitz
Effective wooden board cutting algorithm - Stack Overflow[^]
7 Jul 2014 by Gold$Coin
Hi all,I was creating a control that has a Interface ("IMyInterface") and a ItemsSource of type IEnumerable. on run time the ItemsSource will be assigned with the Collection (ObservableCollection, List or any other collection type) with class type as belowclass with my IMyInterface...
7 Jul 2014 by Gold$Coin
changed the binding type and implemented the other way arround.
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
6 May 2010 by Gordon Kushner
If you try to enumerate through a Dictionary's key collection and attempt to change the values as in the code below, Dictionary _items = new Dictionary();...int i = 0;//Attempt to set the values for this Dictionary item.foreach (string key in...
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() { ...
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: ...
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...
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() { ...
25 Jan 2016 by GravityPhazer
This article demonstrates how you can simply enumerate any generic tree depth-first as well as breadth-first using the described construct. Trees can be serialized binary (using the BinaryFormatter), custom binary and as XML.
6 Dec 2015 by Gregory Morse
WRL Collection library ported to native C++
26 Dec 2011 by hamzah1
Hi,is polymorphism is allowed to used with generics ? if yes can give me a real example real code used polymorphism and what is the difference between ArrayList and Array when we talk about Polymorphismthanks
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...
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...
14 Mar 2012 by HarisJayadev
Hi I have a string array, from which I want part of strings to bind dropdownlist Ex: string[] strArray = new string[10]; strArray[0] = "C:\MyFolder\Software";strArray[1] = "C:\MyFolder\Admin";strArray[2] = "C:\MyFolder\Accounts";strArray[3] =...
18 Feb 2015 by Herbisaurus
I need a collection of objects that will: * allow get, set functionality object via a key (like in a dictionary)* I need to iterate through the collection in a sorted manner, ordered by a "Priority" value* the priority allows multiple values. * the keys can be an int or a string, it...
13 Sep 2019 by honey the codewitch
A B-tree, an AVL tree, and a Splay tree in C#
17 Nov 2019 by honey the codewitch
Implementing full list support over custom data structures in .NET