Proposal: Give annotative names to Key and Value in Dictionary to improve code readability #4422
Unanswered
palazzo-train
asked this question in
Language Ideas
Replies: 1 comment
-
One way to do this might be 1 element tuples: Dictionary<(string title),(string author)> Ideally 1 element tuples would be backed by the Actual element type, not ValueTuple, allowing you to freely cast from |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Add new syntax in Dictionary declaration to annotate the key and value for readability
Motivation
in C# struct, we can know clearly the purpose of a variable by it's name. For example,
Then, i know
b.title
is a type of string and it's referring to title.However in C# dictionary, we can only specify the type
Can we make the code more readable such that the key of the dictionary is type of string and it is referring to title, and the value is type of string and it is referring to author? That means, other people can easily know that d["J.R.R. Tolkien"] is a wrong use of the dictionary when reading the code.
Proposed Syntax
from
to
The
title
andauthor
are only annotation to the type string in the key and the type string in the value. It does not alter anything as of current Dictionary, but the annotationtitle
andauthor
will become some informative meta data used by IDEBeta Was this translation helpful? Give feedback.
All reactions