I have a strange doubt regarding list and dictionary in c#
In a list we add items to list by using the following method
using System.Collections.Gen
I have a class library which accesses a variety of T-sql sprocs; each sproc returns a single row but varying columns. I needed a general purpose solution for an retrieving the values and Dictionary<> provided a much cleaner solution than List<>.
The class common to all of the wrappers declares
public Dictionary datadict = new Dictionary();
and
public Dictionary LoadData(string sproc, string paramName, string paramValue)
Invoking a Reader, the datadict is loaded with
for (int i = Reader.FieldCount; i != 0; i--)
{
datadict.Add(Reader.GetName(i - 1).Trim(), Reader.GetString(i - 1).Trim());
}
and returns datadict to the calling class which can then retrieve the data much like Reader does; E.g.:
datadict = myData.LoadData("spGetSSN", "", "");
ssn1 = datadict["SSN1"];
ssn2 = datadict["SSN2"];
ssn3 = datadict["SSN3"];
Much cleaner for me that List<>.