Guest User

Guest User

  • Tech Writer
  • 357
  • 120.8k

Piece of code analysis

Mar 1 2012 2:15 PM
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)