Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET Default Properties Error
    text
    copied!<p>I have a VB.NET project where I am able to iterate through the keys and values collections of a dictionary object using an index:</p> <pre><code> MyDictionary.Keys(idx) MyDictionary.Values(idx) </code></pre> <p>When this code is taken from the test project and placed into the real project I get the following error:</p> <blockquote> <blockquote> <p>'System.Collections.Generic.Dictionary(Of Double, String).KeyCollection' cannot be indexed because it has no default property.</p> </blockquote> </blockquote> <p>and</p> <blockquote> <blockquote> <p>'System.Collections.Generic.Dictionary(Of Double, String).ValueCollection' cannot be indexed because it has no default property.</p> </blockquote> </blockquote> <p>This is using VB.NET and VS 2008. I don't know what the difference would be from one project to the next that would cause this error. The test is a console application and the program is a winforms app.</p> <p>What conditions would cause the default property of these collections to change?</p> <p><strong>Edit</strong> - Thank you for all of the answers that tell me how to loop through a dictionary. Those, answers, however, do <strong>not</strong> answer my question of why I can use an index in one project and not the other. Should I not be able to copy and paste the code from one .net project to another and have it work the same? And, no, option strict, is not the cause of the problem.</p> <p><strong>Edit</strong> - Attempt to reproduce what I'm seeing:</p> <ul> <li>Create a new VB.NET Console Application using VS 2008</li> <li>Copy and paste the following code into the module:</li> </ul> <pre><code> Imports System.Collections Imports System.Collections.Generic Module Module1 Public dtf As Dictionary(Of Double, String) Public Sub BuildDictionary() dtf = New Dictionary(Of Double, String) dtf.Add(1.0, "1") dtf.Add(0.0, "0") End Sub Public Sub Search() For idx As Integer = 0 To dtf.Keys.Count - 1 If dtf.Keys(idx) = 0 Then Exit Sub End If Next End Sub Sub Main() End Sub End Module </code></pre> <p>In the line in sub search that says "dtf.Keys(idx) = 0" place your cursor after the right parenthesis and backspace you should get a tooltip that says, "&lt;Extension&gt; ElementAtOrDefault(index as Integer) as Double - <strong>index:</strong> the zero based element of the index to retrieve.</p> <p>I am not getting that in my other project. Even though it seem I have the same references and settings.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload