>>>>>>>>>>Hi Viv,
>>>>>>>>>>
>>>>>>>>>>If I change definition of the TableSchema class to be
>>>>>>>>>>
>>>>>>>>>>public class TableSchema
>>>>>>>>>>{
>>>>>>>>>>
>>>>>>>>>>internal String TableName;
>>>>>>>>>>
>>>>>>>>>>public List<ColumnSchema> Columns = new List<ColumnSchema>();
>>>>>>>>>>
>>>>>>>>>>}
>>>>>>>>>>
>>>>>>>>>>then how would I retrieve column schema for particular column name ?
>>>>>>>>>
>>>>>>>>>
var columnSchema = Columns.Where(x => x.ColumnName == "Name").FirstOrDefault();
>>>>>>>>
>>>>>>>>Good idea! So, you think it's better than using dictionary, right?
>>>>>>>>
>>>>>>>>If so, I'll try to change to your code and use a List.
>>>>>>>
>>>>>>>Don't see much point in a Dictionary here. And IEnumerable might be better the List....
>>>>>>
>>>>>>A Dictionary should give close to O(1) look up time, whereas an IEnumerable will be O(n). Depending on the size of the list and how often its used, the speed difference is probably negligible. It is easy enough to create the Dictionary though:
>>>>>>
Dictionary<string, ColumnSchema> columnTypes;
>>>>>>
>>>>>> using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SchemaOnly))
>>>>>> {
>>>>>>
>>>>>> columnTypes = (from DataRow r in reader.GetSchemaTable().AsEnumerable()
>>>>>> select new ColumnSchema
>>>>>> {
>>>>>> ColumnName = (string) r["ColumnName"],
>>>>>> ColumnSize = (Int32) r["ColumnSize"],
>>>>>> DbType = (SqlDbType) r["ProviderType"],
>>>>>> DataType = (Type) r["DataType"]
>>>>>> }).ToDictionary(cs=> cs.ColumnName);
>>>>>> }
Fair point. Guess we don't know enough about the context in which the collection will be used. One downside of a Dictionary is that it makes it more difficult to access an item by anything other than the ColumnName?
>>>>
>>>>But in this context, I don't think the dicitonary is needed. A simple IEnumerable should suffice.
>>>
>>>Naomi stated she wanted to retrieve the ColumnSchema data by the column name. I would say that is more than enough justification for a dictionary.
>>
>>I guess I missed that part. What about a tuple?
>
>A list of tuples doesn't provide O(1) lookup time, and any info contained in the other part of the tuple is already in the ColumnSchema class. Is there something wrong with using a Dictionary that I'm not aware of?
Nah, just asking a question. I would have probably used a dictionary given the requirements, but who knows for sure.