3
Answers

Piece of code analysis

S

S

12y
1.1k
1
Hi,

Id like to know what this piece of code is doing please. My comments are next to each expression as to what I think is happening.
 
 // Resetting the generic type T and assigning to a  local variable t

T t = default(T);

// Assigning the ExecuteReader method to a local  variable named reader in order to get the result of the  command.
   
var reader = command.ExecuteReader();
   
// Whilst the reader variable is reading the rows.

if (reader.Read())
   
// Pass the reader variable to the make method and  assign it to t.

t = make(reader);
   
// return the value type t.

return t;

This is the Method signature declaration

public static T ReadList<T>(Func<IDataReader, T> make)

Answers (3)