How do I return a element using LINQ query from an ObservableCollection?

Viewed 165

I have an ObservableCollection:

public ObservableCollection<NurDeviceWatcherInfo> KnownDevices = new ObservableCollection<NurDeviceWatcherInfo>();

NurDeviceWatcherInfo has these string properties: Address, ConnState, Info, Name, Spec, SpecStr, Tag, TransportType.

What I am trying to use is:

NurDeviceWatcherInfo device = from NurDeviceWatcherInfo in KnownDevices 
                                where NurDeviceWatcherInfo.Name.Contains("NUR") 
                                select new NurDeviceWatcherInfo();

For which I receive the following error:

Severity Code Description Project File Line Suppression State Error CS0266 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'NurApiDotNet.UWP.NurDeviceWatcherInfo'. An explicit conversion exists (are you missing a cast?)

What would be the correct syntax?

1 Answers

I solved it using :

device = KnownDevices.Where(x => x.Name.Contains("NUR")).FirstOrDefault();
Related