Hi, Use the "as" operator instead:
Database database = MyList.Where(o => o.GetType().FullName == "Comp.Database").FirstOrDefault() as Database; Lee --- http://www.jiba-jaba.com -- Public discussion -----Original Message----- From: [email protected] on behalf of graphicsxp Sent: Fri 22/05/2009 11:01 To: DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting Subject: [DotNetDevelopment] [LINQ] Testing for null value Hi, Consider the following : List MyList = new List() {null, 2}; Database database = (Database)MyList.Where(o => o.GetType().FullName == "Comp.Database").FirstOrDefault(); Since the first element is null, this will raise an exception. How can I change the above to handle that directly in the Linq query ? Thanks
<<inline: winmail.dat>>
