List<object> _list = new List<object>(); public object Get => _list.Where( x => x.GetType() == typeof( int ) ).First();
Using the above code will System.InvalidOperationException when the length of Where is zero.
public object Get2 { get { var where = _list.Where( x => x.GetType() == typeof( int ) ); if( 0 < where.Count() ) { return where.First(); } return null; } }
So, I use it to fix this, but is there a way to make the code cleaner?
source share