Fast add huge HashSet<string> to ListBox [duplicate] - c#

This question already has answers here:
Slow showing / drawing dialogue with ListBox?
(3 answers)
How to select all items in a ListBox really fast?
(5 answers)
Displaying a large number of strings in WinForms listbox/listview controls
(2 answers)
Closed 3 years ago.
Hellow! How can I add huge (~2000000 records) HashSet to ListBox? I have used foreach and inside listBox1.Add(...), but it is slow. I thinck that I'm to use AddRange(...), but I can't do that becouse I do not know how to convert HashSet to object[].
May be you know another way to fast load hashset to listbox?

Related

How to Increase array memory space C# [duplicate]

This question already has answers here:
change array size
(15 answers)
How to resize multidimensional (2D) array in C#?
(7 answers)
Closed 9 months ago.
I'm tying to create an method which accepts two parameter and rewrite them by increasing their memory space by one
public void expand(string[] array,double[,] data)
{
}

How to iterate over all elements in array(or list) with LINQ? [duplicate]

This question already has answers here:
Linq style "For Each" [duplicate]
(6 answers)
Closed 3 years ago.
I am new to LINQ and i want to switch onto it from traditional loops
I have an array of GameObjects and I just want to iterate over all of them and set one of their component enabled, and I wanna know if there is 1 line elegant way with LINQ to replace foreach or for loop's version
gameObjects.ToList().ForEach(x => {do Stuff with list});
Some reading on forEach in C# however. Could be interesting: https://blogs.msdn.microsoft.com/ericwhite/2009/04/08/why-i-dont-use-the-foreach-extension-method/

Check a list has set of values [duplicate]

This question already has answers here:
Determine if a sequence contains all elements of another sequence using Linq [duplicate]
(4 answers)
Closed 8 years ago.
I have two sting lists
List<string> list1=new List(){"1","2","3"};
List<string> list2=new List(){"1","2"};
What will be the easiest way to check if list1 contains the values in list2.
How about
list1.Except(list2).Any();
Try using
[listName].Except(SecondListName).Any();
This should work.

How to randomize collection of EF models [duplicate]

This question already has answers here:
Linq to Entities, random order
(12 answers)
Randomize a List<T>
(28 answers)
Closed 9 years ago.
I have a User object that has a collection of Items.
How can I randomize the Items so they dont' appear in the exact same order everytime.
I'm currently ordering by SortOrder (integer), but this will obviously be in the same order everytime.
#foreach(UserItems ui in Model.User.Items.OrderBy(x => x.SortOrder))
{
}
Here's a little trick:
#foreach(UserItems ui in Model.User.Items.OrderBy(x => Guid.NewGuid()))
{
}

Check for empty fields in form [duplicate]

This question already has answers here:
Find all controls in WPF Window by type
(17 answers)
Checking for unfilled fields with PHP
(3 answers)
Closed 9 years ago.
Is it possible to check a form for any empty text boxes rather than having to put a check on each individual text box with an if? Any help would be much appreciated.
I'm not that familiar with WPF, but you might try to get a list of the child-elements in a form, and for each, check if they are of type Textbox. If so, perform your validation.

Categories