Questions tagged [addrange]
83 questions
453
votes
3 answers
Is there an AddRange equivalent for a HashSet in C#
With a list you can do:
list.AddRange(otherCollection);
There is no add range method in a HashSet.
What is the best way to add another ICollection to a HashSet?

Stefanos Kargas
- 10,547
- 22
- 76
- 101
185
votes
13 answers
ObservableCollection Doesn't support AddRange method, so I get notified for each item added, besides what about INotifyCollectionChanging?
I want to be able to add a range and get updated for the entire bulk.
I also want to be able to cancel the action before it's done (i.e. collection changing besides the 'changed').
Related Q
Which .Net collection for adding multiple objects at once…

Shimmy Weitzhandler
- 101,809
- 122
- 424
- 632
100
votes
6 answers
How to add a range of items to an IList?
There is no AddRange() method for IList.
How can I add a list of items to an IList without iterating through the items and using the Add() method?

mohsen dorparasti
- 8,107
- 7
- 41
- 61
21
votes
3 answers
List.AddRange implementation suboptimal
Profiling my C# application indicated that significant time is spent in List.AddRange. Using Reflector to look at the code in this method indicated that it calls List.InsertRange which is implemented as such:
public void InsertRange(int index,…

shojtsy
- 1,710
- 3
- 17
- 24
9
votes
2 answers
How can I improve performance of an AddRange method on a custom BindingList?
I have a custom BindingList that I want create a custom AddRange method for.
public class MyBindingList : BindingList
{
...
public void AddRange(IEnumerable vals)
{
foreach (I v in vals)
Add(v);
}
}
My…

Rachel
- 130,264
- 66
- 304
- 490
8
votes
5 answers
Can't append one list to another in C#... trying to use AddRange
Hi I'm trying to append 1 list to another. I've done it using AddRange() before but it doesn't seem to be working here... Here's the code:
IList resultCollection = ((IRepository)this).SelectAll(columnName, maxId - startId + 1, startId); …

Matt
- 5,547
- 23
- 82
- 121
7
votes
4 answers
c# Linq `List.AddRange` Method Not Working
I have an interface defined as below:
public interface TestInterface{
int id { get; set; }
}
And two Linq-to-SQL classes implementing that interface:
public class tblTestA : TestInterface{
public int id { get; set; }
}
public class…

Jimbo
- 22,379
- 42
- 117
- 159
7
votes
4 answers
ToCharArray equivalent for List
How do you split a string to a List? I'm looking for the equivalent of ToCharArray but instead to make it a List.
string data = "ABCDEFGHIJ1fFJKAL";
List datalist = new List();
datalist.AddRange(new List{"A","B","C"});
How…

Johnado
- 73
- 1
- 1
- 3
7
votes
4 answers
List.AddRange with IEnumerable parameter not working?
I have the following scenario where I want to add some items to a List...
List items = new List();
IEnumerable addItems = someCollection.Where(...);
items.AddRange(addItems);
Using this code, no items are added to the list but if I add a…

John
- 605
- 2
- 7
- 17
6
votes
1 answer
Extending List (AddRange) in O(1) in C#
I'm trying to find a solution in C# to extending a list in O(1).
List's AddRange() method is of course an O(n) operation.
This should have been something that LinkedList supports, but LinkedList doesn't have a method like AddRangeLast(), and trying…

Liron Achdut
- 881
- 10
- 12
6
votes
2 answers
Add a List to another List that is either null or not null
Consider the the piece of code below. I need to call the method CreateOrAddToLists() in a loop. First time the method is called the two lists casedata.Cases and casedata.Documents will be null, hence I can populate by assigning cases to…

hsop
- 3,546
- 3
- 20
- 19
6
votes
2 answers
Why does adding a list to another list, using add range, remove the elements from the first list?
Consider the following example:
IEnumerable groupsToAdd = new List();
List groups1 = new List() { 1,2,3 };
List groups2 = new List() { 3,4,5 };
groupsToAdd = groups1.Where(g => false ==…

Letseatlunch
- 2,432
- 7
- 28
- 33
6
votes
2 answers
Add Range of items to list without duplication
I have a List of List of Strings, and I need to use the AddRange() Function to add set of items to it, but never duplicate items.
I used the following code :
List
- > eList = new List
- >();
List
- > mergedList = new…

AyaZoghby
- 341
- 3
- 7
- 16
5
votes
2 answers
list.AddRange Cannot implicitly convert type 'void'
namespace SubscriptionWebsite.PlaceHolders
{
public class TreeData
{
public int ID { get; set; }
public int? ParentLocationID { get; set; }
public string name { get; set; }
public int? Locationlevel { get;…

user2811133
- 69
- 2
- 7
5
votes
4 answers
How to use Combo Box AddRange in WPF C#
I have a little problem, I have an array and I want to add that in a Combobox, so I want to use the AddRange method, but it isn't available in WPF, is there a way that I can do it in the combobox?
Thanks.

Sandeep Bansal
- 6,280
- 17
- 84
- 126