Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is this linq query return a boolean and not the first result of the select?

Tags:

c#

linq

I have a string array with 5 items. How to get one of these 5 items by a linq query?

Code below returns only a boolean true.

string[] allWebTemplateSettings =SiteLidmaatschapSettings.Current.ProvisioningSettings;
var webTemplate = allWebTemplateSettings
           .Select(x => x.StartsWith(string.Format("Template:{0}", web.WebTemplate)))
           .FirstOrDefault();
like image 1000
Ola Avatar asked May 01 '15 08:05

Ola


1 Answers

Use Where instead of Select:

var webTemplate = allWebTemplateSettings.Where(x => x.StartsWith(string.Format("Template:{0}", web.WebTemplate))).FirstOrDefault();
like image 54
Ham3d Avatar answered Oct 14 '22 08:10

Ham3d