当前位置:网站首页>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边栏推荐
- Length of the longest integrable subarray
- MySQL storage engine
- 2022-2028 global elevator emergency communication system industry research and trend analysis report
- CSDN常用复杂公式模板记录
- Teach you how to use Hal library to get started -- become a lighting master
- Rust book materials - yazhijia Library
- 优质的水泵 SolidWorks模型素材推荐,不容错过
- ArrayList analysis 1-cycle, capacity expansion, version
- Redis - cache penetration, cache breakdown, cache avalanche
- [2023 MediaTek approved the test questions in advance] ~ questions and reference answers
猜你喜欢

20220215 CTF misc buuctf the world in the mirror the use of stegsolve tool data extract
![[untitled]](/img/96/7f26614bbdcce71006e38ee34ab216.jpg)
[untitled]

Bugku CTF daily one question dark cloud invitation code

Implementation of OSD on Hisilicon platform (1)

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

PyTorch安装并使用gpu加速

CMU15445 (Fall 2019) 之 Project#1 - Buffer Pool 详解

写给 5000 粉丝的一封信!

Vulnerability discovery - App application vulnerability probe type utilization and repair

2022-2028 global capsule shell industry research and trend analysis report
随机推荐
Multi graph explanation of resource preemption in yarn capacity scheduling
Yboj mesh sequence [Lagrange interpolation]
C language file operation for conquering C language
Rhai - rust's embedded scripting engine
HDU 2488 A Knight's Journey(DFS)
写给 5000 粉丝的一封信!
Length of the longest integrable subarray
Wechat official account development (1) introduction to wechat official account
P4学习——p4runtime
CentOS install MySQL
A single element in an ordered array
Longest valid bracket
Plot size and resolution with R markdown, knitr, pandoc, beamer
2022-2028 global mobile scanning radiology room industry survey and trend analysis report
MySQL index test
HDU 2488 A Knight's Journey(DFS)
剑指 Offer 18. 删除链表的节点
C # Generate PPK files in Putty format (passthrough support)
Oracle-数据完整性
P4 learning - p4runtime