Text type as Dictionary key

This works:

  Dim s As String = "StringValue"
  Dim d As New Dictionary
  d.Value(s) = "Dictionary Value"

But this does not:

  Dim t As Text = "TextValue"
  Dim d As New Dictionary
  d.Value(t) = "Dictionary Value"

I get KeyNotFoundException. Now my question is WHY and what’s the correct way for using Text variables with this example?

[code]Dim t As Text = “TextValue”
Dim d As New Dictionary
d.Value(t) = “Dictionary Value”

MsgBox(d.Value(“TextValue”)) <–– “TextValue” is a String, not a Text[/code]

So either prepend the code with

Using Xojo.Core

or do this conversion:

MsgBox(d.Value(CType("TextValue", Text)))

Always thought Text and String types are interchangeable. Oh well…

Text has an implicit conversion to String, but not the other way. That is why you have to use .toText for a string to be affected to a Text variable.