dotnet / dotnet/vblang

Dictionary strong key names

Open
#234 16 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

I suggest to add this form to the dictionary initializer:
```
Dim Cities As New Dictionary(Of String, Integer)
From {NewYork = 10, London = 5, Cairo = 12}
```
Note that:
1- I Suggest also to add an implicit line continuation arround the From keyword.
2- No quotations around key names, not only for simplicity, but also to force us to choose valid names to be used as members (see 3).
3- The complier can use this syntax to define strong key names seen only in the dictionary scope so they don't affect other variable names. These keys can be used as follows:
```
Msgbox(Cities.Cairo)
Cities.London = 3
```
Or by the traditional ways:
```
Msgbox(Cities!Cairo)
Cities(London) = 3
```
This will prevent key names mistyping bugs, and give us intillisense autocompletion.

To do this, the compiler can generate a new class that inherits the Dictionary class, and add properties to it with the key names from the initializer!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.