Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Linq FirstOrDefault() null check in c#
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { try{ //Your code goes here PlayerSettingsResponsible objPlayer = new PlayerSettingsResponsible(); objPlayer.Designation="DesigOne"; objPlayer.IdPlayerDeviceSettingsType=1;//Change equal to 2 gives null objPlayer.Value="ValueOne"; List<PlayerSettingsResponsible> objPlayerList = new List<PlayerSettingsResponsible>(); objPlayerList.Add(objPlayer); PlayerSettingsResponsible objPlayerSearch = objPlayerList.FirstOrDefault(r => r.IdPlayerDeviceSettingsType != null && r.IdPlayerDeviceSettingsType == 1); if(objPlayerSearch == null) { Console.WriteLine("Null Object"); return; } string sValue = objPlayerSearch.Value; Console.WriteLine(sValue); } catch(Exception e){Console.WriteLine("Exception: "+e.Message);} } } public class PlayerSettingsResponsible { public string Designation { get; set; } public int? IdPlayerDeviceSettingsType { get; set; } public string Value { get; set; } } }
run
|
edit
|
history
|
help
0
Padma. C#
First code
Timespan Calculator
WebScrape using Regex
convert String To Guid
Examples of JS-Like higher-order functions in C#
Overriding
Random number between 1 - 100 between each value of 10 there will be a differnt message
BiologyQuestions
Datediff in c#