Unlike a List<> A HashSet is a List with no duplicate members. Because a HashSet is constrained to contain only unique entries, the internal structure is optimized for searching (compared with a list) – it is considerably faster Adding to a HashSet returns a boolean – false if addition fails due to already existing in […]
Tag: list
What is the difference between HashSet
Change some value inside List
Let’s say you have a List of T. And there are Property1, Property2, Property3 in T. If you want to change the value of Property2 in T then you can use: var myList = List<T>; foreach (var item in myList) { item.Property2 = newValue; } or var myList = List<T>; myList.ForEach(x => x.Proprty2 = newValue); […]
Pop, Push, Shift and Unshift Array Methods in JavaScript
pop(): Remove an item from the end of an array (returns the removed item) push(parameterToAdd): Add items to the end of an array (returns the new array length) shift(): Remove an item from the beginning of an array (returns the removed item) unshift(parameterToAdd): Add items to the beginning of an array (returns the new array […]
Convert comma separated string into a List in C#
string myList = “9,3,12,43,2”; List<int> intList = myList.Split(‘,’).Select(int.Parse).ToList();
Converting a List to a comma separated string in C#
List<int> list = new List<int>() {1,2,3}; string.Join<int>(“,”, list) Join has generic overloads. It is so much easier to use it in that way to convert your list to the different types.
Convert List to List in one line in C#
string sNumbers = “1,2,3,4,5”; var numbers = sNumbers.Split(‘,’).Select(Int32.Parse).ToList();
How to find the first missing value in a series in MS SQL
Let’s say we have this values in the database: num — 1 2 4 5 6 8 9 11 To Find the first missing value, we can use this: ;WITH CteRN AS( SELECT *, RN = num – ROW_NUMBER() OVER(ORDER BY num) FROM tbl ) SELECT TOP 1 num – RN FROM CteRN WHERE RN […]
How to select distinct rows in a datatable in C#
dataTable.DefaultView.ToTable(true, “target_column”); first parameter in ToTable() is a boolean which indicates whether you want distinct rows or not. second parameter in the ToTable() is the column name based on which we have to select distinct rows. Only these columns will be in the returned datatable. If you need to get distinct based on two columns: dataTable.DefaultView.ToTable(boolean, params string[] columnNames)
Convert a Comma-Delimited List to a Table in SQL
You can check the example code:
Add blank item at top of dropdownlist
drpList.Items.Insert(0, new ListItem(String.Empty, String.Empty)); drpList.SelectedIndex = 0;