Editing an item in a list

After adding an item to a list, you can replace it by writing list[someIndex] = new MyClass(); You can modify an existing item in the list by writing list[someIndex].SomeProperty = someValue; EDIT: You can write var index = list.FindIndex(c => c.Number == someTextBox.Text); list[index] = new SomeClass(…);

Replace an object in a list of objects

You have to replace the item, not the value of customListItem2. Just replace following: customListItem2 = customListItems.Where(i=> i.name == “Item 2”).First(); customListItem2 = newCustomListItem; With this: customListItem2 = customListItems.Where(i=> i.name == “Item 2”).First(); var index = customListItems.IndexOf(customListItem2); if(index != -1) customListItems[index] = newCustomListItem; Edit: As Roman R. stated in a comment, you can replace the …

Read more

NUnit comparing two lists

If you’re comparing two lists, you should use test using collection constraints. Assert.That(actual, Is.EquivalentTo(expected)); Also, in your classes, you will need to override the Equals method, otherwise like gleng stated, the items in the list are still going to be compared based on reference. Simple override example: public class Example { public int ID { …

Read more

convert .NET generic List to F# list

Try List.ofSeq in the Microsoft.FSharp.Collections namespace. # List.ofSeq : seq<‘T> -> ‘T list It’s not specifically for System.Collections.Generic.List<T>, but for IEnumerable<T> (seq<‘T> in F#) types in general, so it should still work. (It’s also not strictly built into the F# language, but neither is List<T> built into C# or VB.NET. Those are all part of …

Read more

Convert an enum to List

Use Enum‘s static method, GetNames. It returns a string[], like so: Enum.GetNames(typeof(DataSourceTypes)) If you want to create a method that does only this for only one type of enum, and also converts that array to a List, you can write something like this: public List<string> GetDataSourceTypes() { return Enum.GetNames(typeof(DataSourceTypes)).ToList(); } You will need Using System.Linq; …

Read more