Answers for "c# get item from list"

C#
6

c# list index

// Get the first item from the list

using System.Linq;

var myList = new List<string>{ "Yes", "No", "Maybe"};
var firstItem = myList.ElementAt(0);

// Do something with firstItem
Posted by: Guest on August-13-2020
3

find a value in list of objects in c#

var item = TextPool.FirstOrDefault(o => o.Name == "test");
if (item != null)
       item.value = "Value";
Posted by: Guest on April-03-2020
1

get both item and index in c#

// add this to your namespace
public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> source)
{
    return source.Select((item, index) => (item, index));
}

//do something like this

foreach (var (item, index) in collection.WithIndex())
{
    DoSomething(item, index);
}
Posted by: Guest on October-02-2020
0

c# get all elements from list

You could get the Customers like this:

using System.Linq;

collectionCarts.SelectMany(c => c.OrderList.Select(o => o.Customer));
Posted by: Guest on March-16-2021

Code answers related to "c# get item from list"

C# Answers by Framework

Browse Popular Code Answers by Language