first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

C# 2.0 Code: Using a Generic List<T> to Build an Array from a Generic Dictionary<String, Object>

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&lt;IDataParameter&gt; list =
    new List&lt;IDataParameter&gt;( parameterCollection.Count );
foreach ( KeyValuePair&lt;String, Object&gt; kvp in parameterCollection )
{
    list.Add( GetParameter( dbmsCommand, kvp.Key, kvp.Value ) );
}
return list.ToArray();

The GetParameter() member generates an object that implements IDataParameter.

mod date: 2007-08-29T19:37:28.000Z