John Bolter
asked on
Help with some (not simple) LINQ
Hi, more LINQ woes. I really would appreciate some help. My code that doesn't work is below.
Thank you
John
Thank you
John
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication348
{
class Program
{
static void Main(string[] args)
{
List<String> numbers = new List<String> { "one", "one", "one", "two", "three" };
String searchNumber = "one";
var found1 = (
from x
in numbers
where x == searchNumber
select new { x }
).ToList().Take(1); //I want found1 to be a string and have value 'one'
searchNumber = "twenty";
var found20 = (
from x
in numbers
where x == searchNumber
select new { x }
).ToList().Take(1).DefaultIfEmpty("not found"); //I want found20 to be a string and have value 'not found'
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.