linq - For a database collection, should FirstOrDefault return null? -


i puzzled expected behaviour or family of linq methods singleordefault, firstordefault, lastordefault , elementatordefault methods, operating on database.

should return:

  1. null, or
  2. a new object populated default values?

they return item in sequence or default value of item if sequence empty (or in case of 'elementatordefault' if index specified out of range).

the below excerpt documentation default:

the solution use default keyword, return null reference types , 0 numeric value types. structs, return each member of struct initialized 0 or null depending on whether value or reference types.

link default documentation: https://msdn.microsoft.com/en-us/library/xwth0h0d.aspx


Comments