One of the many, many ways to use Generics in C# 2.0 is to build a strongly-typed Array from a Generic Dictionary<String, Object>. This form of Dictionary is useful for generating parameters for data commands. The challenge is to get this general-purpose collection of parameters into a “real” array of parameters that can be used by the .NET Framework:
List<IDataParameter> list =
new List<IDataParameter>( parameterCollection.Count );
foreach ( KeyValuePair<String, Object> kvp in parameterCollection )
{
list.Add( GetParameter( dbmsCommand, kvp.Key, kvp.Value ) );
}
return list.ToArray();
The GetParameter() member generates an object that implements IDataParameter.