List<object> _list = new List<object>();
public object Get => _list.Where( x => x.GetType() == typeof( int ) ).First();
Using the above code will cause a 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 am using it to fix this, but is there a way to make the code cleaner?