当前位置:网站首页>Is the public read-only field with immutable structure valid- Does using public readonly fields for immutable structs work?
Is the public read-only field with immutable structure valid- Does using public readonly fields for immutable structs work?
2022-07-01 00:56:00 【Saffron】
problem :
Is this a proper way to declare immutable structs? Is this the right way to declare immutable structures ?
public struct Pair{ public readonly int x; public readonly int y; // Constructor and stuff}I can't think of why this would run into problems, but I just wanted to ask to make sure. I can't think of why this is a problem , But I just want to ask .
In this example, I used ints. In this case , I use the int.What if I used a class instead, but that class is also immutable, like so? If I use a class , But this class is also immutable , Like this ?That should work fine too, right? This should also work properly , Right ?
public struct Pair{ public readonly (immutableClass) x; public readonly (immutableClass) y; // Constructor and stuff}(Aside: I understand that using Properties is more generalizable and allows changing, but this struct is intended literally to just store two values. I'm just interested in the immutability question here.)( Aside : I understand that using attributes is more general and allows changes , But this structure actually only stores two values . I'm just interested in the invariance problem here .)
Solution :
Reference resources : https://stackoom.com/en/question/PRJk边栏推荐
- Join table query select generation
- P4学习——p4runtime
- Can JDBC based on openjdk connect to MySQL?
- 给按钮的边框和文字设置不同的背景色
- 什么是产品思维
- [untitled]
- History of deep learning
- Rust controls Dajiang programmable UAV Tello
- Sword finger offer 18 Delete the node of the linked list
- SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding
猜你喜欢

Pytorch installs and uses GPU acceleration

20220215 CTF misc buuctf the world in the mirror the use of stegsolve tool data extract

Oracle临时表详解

Sword finger offer 18 Delete the node of the linked list

2022-2028 global carbon fiber room scraper system industry research and trend analysis report

Oracle temporary table explanation

The programmer's girlfriend gave me a fatigue driving test

C#生成putty格式的ppk文件(支持passphrase)

P4 learning - Basic tunneling

PyTorch安装并使用gpu加速
随机推荐
Simple application example of rhai script engine
Mindjet mindmanager2022 mind map decompression installer tutorial
2022-2028 global single travel industry research and trend analysis report
Problem solving: how to manage thread_local pointer variables
20220215-ctf-misc-buuctf-ningen--binwalk analysis --dd command separation --archpr brute force cracking
Stack frame
Host FL Studio fruit music production daw20.9
20220216 misc buuctf another world WinHex, ASCII conversion flag zip file extraction and repair if you give me three days of brightness zip to rar, Morse code waveform conversion mysterious tornado br
Examples of topological sequences
left join左连接匹配数据为NULL时显示指定值
Tide - rust web framework based on async STD
2022-2028 global ultra high purity electrolytic iron sheet industry research and trend analysis report
Deployment of mini version message queue based on redis6.0
Date类的实现
Introduction to ES6 promise, new features of ES7 and es8 async and await
ArrayList analysis 1-cycle, capacity expansion, version
2022就要过去一半了,挣钱好难
2022-2028 global carbon fiber room scraper system industry research and trend analysis report
对libco的一点看法
Thoughts on the future of data analysis in "miscellaneous talk"