[Gambas-user] Collection(gb.IgnoreCase)

T Lee Davidson t.lee.davidson at gmail.com
Thu May 4 15:03:19 CEST 2023


On 5/4/23 01:20, Mayost Sharon wrote:
> I understand that this:
> MyCollection = ["key1": "v1"]
>    MyCollection = ["KEY1": "v1"]
> In the end there will be only one in the collection
> 
> But it would seem that even when I want to know the certain value that is in the collection
> Print MyCollection["key1"]
> that it will not be case sensitive

But, it *will* be case sensitive because you have changed the Mode of MyCollection by assigning to it an inline collection that, 
by default, is case sensitive.

The result of "MyCollection = New Collection(gb.IgnoreCase)" is you have an empty collection that is case-insensitive. Then, you 
*overwrite* that empty collection with a case-sensitive collection with one key/value pair. It is, essentially, a *different* 
collection.

Try the following, first as it is, and then with the commented line uncommented:
[code]
Public Sub main()

   Dim MyCollection As New Collection(gb.IgnoreCase)

   ' MyCollection = ["KEY1": "v1"]
   MyCollection.Add("v1", "key1")
   MyCollection.Add("v1", "Key1")
   For Each sValue As String In MyCollection
     Print MyCollection.Key, sValue
   Next

End
[/code]

See the difference?


-- 
Lee



More information about the User mailing list