how does IConvertible works

258 views Asked by At

I have the following code which I got from the internet. I am not sure about the use of IConvertible. MSDN says:

"This interface provides methods to convert the value of an instance of an implementing type to a common language runtime type that has an equivalent value."

Is it meant that, I can assign anything to IConvertible and while using it converts it to the implementing type?

For example, in below example I pass parameters as key-value pair where key is string and value is IConvertible.

SqlParameter object = new SqlParameter(param.Key, param.Value)

SqlParameter object takes key as string and value as depending on the type declared in the table or stored procedure. How does it exactly works here?

private SqlCommand GetCommand(string procedureName,   
IEnumerable<KeyValuePair<string, IConvertible>> parameters)
{
  foreach (var param in parameters)
  {
      command.Parameters.Add(new SqlParameter(param.Key, param.Value));
  }
}
0

There are 0 answers