Answers for "find object in list then select that object into a new object c#"

C#
1

select a object from list based on a value csharp

// this will return the first correct answer,
// or throw an exception if there are no correct answers
var correct = answers.First(a => a.Correct); 

// this will return the first correct answer, 
// or null if there are no correct answers
var correct = answers.FirstOrDefault(a => a.Correct); 

// this will return a list containing all answers which are correct,
// or an empty list if there are no correct answers
var allCorrect = answers.Where(a => a.Correct).ToList();
Posted by: Guest on April-08-2021

Code answers related to "find object in list then select that object into a new object c#"

C# Answers by Framework

Browse Popular Code Answers by Language