admin管理员组文章数量:1302374
Is ReadonlySet
means set of ReadOnly
properties as same as ReadOnlyCollection in C#?
I am not able to find out any document for it from anywhere. Could you please let me know what is the use of ReadonlySet
and How can we do implementation of it?
let readonly: Readonly<number> = 1;
let readonlySet: ReadonlySet<number> = ???//
Is ReadonlySet
means set of ReadOnly
properties as same as ReadOnlyCollection in C#?
I am not able to find out any document for it from anywhere. Could you please let me know what is the use of ReadonlySet
and How can we do implementation of it?
let readonly: Readonly<number> = 1;
let readonlySet: ReadonlySet<number> = ???//
Share
edited Jul 26, 2019 at 19:08
Ian
6,1546 gold badges45 silver badges76 bronze badges
asked Jan 18, 2018 at 15:45
Ramesh RajendranRamesh Rajendran
38.7k49 gold badges157 silver badges239 bronze badges
3
-
@T.J.Crowder I thought the function of
ReadOnlySet
is same asReadOnlyCollection
which is I have using in C#(backend). I don't get any document for this. – Ramesh Rajendran Commented Jan 18, 2018 at 15:50 - (Yes, I saw the edit.) If it's in code you're using, you must be able to figure out what's providing it and, from there, find the documentation or source code. Without knowing what class you're talking about, it's hard to help you. In general: No, a set is not the same as a collection. A collection can contain the same value twice. A set cannot. – T.J. Crowder Commented Jan 18, 2018 at 15:51
- @T.J.Crowder There have no documentation, then what will I do? Could you please let me know if you found any documentation about this? – Ramesh Rajendran Commented Jan 18, 2018 at 15:52
1 Answer
Reset to default 12ReadonlySet
is a type similar to Set
, but it does not have a add
/ delete
method, so elements can only be added during construction:
const regular: Set<number> = new Set([1,2,3]);
regular.add(4);
const readonly: ReadonlySet<number> = new Set([1,2,3]);
readonly.add(4) //fails, add not a function
Reference
Unlike the readonlySet in C# you referenced, typescripts ReadonlySet is not actually a class/constructor. Its just a type. As typescript has duck typing, the Set
is kind of a superclass to ReadonlySet
, so the type can be "typecasted". This is actually only for typechecking, it has no runtime influence.At runtime, it's just a JavaScript Set
.
本文标签: javascriptDetails About ReadonlySetStack Overflow
版权声明:本文标题:javascript - Details About: ReadonlySet? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741700655a2393268.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论