I am attempting to dump hybrid dictionary keys to an excel worksheet range, but it is not performing as expected. Here’s my code.
Dim ExcelApplication As Excel.Application = New Excel.Application
Dim ExcelWorkbook As Excel.Workbook = ExcelApplication.Workbooks.Add
Dim SheetName As String = "Area Information"
Dim ExcelAreaBalanceWorksheet As Excel.Worksheet = CType(ExcelWorkbook.Sheets(1), Excel.Worksheet)
Dim BAGenByKVDictionary As New HybridDictionary
'code to populate hybriddictionary
Dim Rng As Excel.Range = ExcelAreaBalanceWorksheet.Range("a1", _
ExcelAreaBalanceWorksheet.Cells(BAGenByKVDictionary.Count, 1))
Rng.Value = ExcelApplication.WorksheetFunction.Transpose(BAGenByKVDictionary.Keys.ToString)
When I try to pass the keys to Excel, it passes System.Collections.Hashtable+ValueCollection for all cells instead of passing the keys.
This is because ToString() on the HybridDictionary does not override the base
Objectimplementation, which is defined, in part as:In order to retrieve the keys as an array of strings, there are numerous methods, but I always prefer the most straightforward approach, a loop: