Questions tagged [value-type]
In computer science, the term value type is commonly used to refer to one of two kinds of data types: Types of values or Types of objects with deep copy semantics.
value-type
596
questions
1
vote
0
answers
98
views
Are Value Classes allowed to exhibit change? [closed]
The doc for Value Based Classes specify:
Instances of a value-based class:
are final and immutable (though may contain references to mutable objects);
If I defined a value class Foo, which had a ...
-1
votes
3
answers
90
views
C++ function as a parameter where its parameter can be passed by value or by reference
I have the following functions where processArray is a generic function that is used to process an array. A function is passed to it as a parameter so that each element can also be processed.
template&...
0
votes
1
answer
66
views
Garbage Collection of value types inside an array
Suppose I have some small data type - for example a simple point implementation. I can either implement this type as a reference type (class), or as a value type (struct).
public class PointClass
{
...
3
votes
2
answers
118
views
ValueType as property in class
I am a bit confused with a concept of value types as properties in a class.
As far as I understand, when getter is called - a copy of value type is returned.
Let's have an example:
public struct Point
...
0
votes
2
answers
93
views
When trying to iterate over an integer array using 'foreach' it is possible to define the element's type as 'char'
I have encountered a very interesting thing in C#. For example, if you try to iterate over an array of integers using foreach statement, you basically can define item's type as char. For reference you ...
2
votes
2
answers
439
views
If c# struct is a value type why does default Equals need to use reflection?
I always thought that C# structs being value types meant that a comparison would be something like checking two blocks of memory are the same, but I just read https://learn.microsoft.com/en-us/dotnet/...
2
votes
3
answers
167
views
Do strings get boxed in C#? [duplicate]
Update Jan 5, 2024: the answer at this link appears to show that the C# compiler completely removes the object cast when trying to cast a string to an object: https://stackoverflow.com/a/51381643/...
1
vote
1
answer
64
views
When requiring a Value type, is there some merit to breaking down reference types rather than creating a deep-copy method?
The reason I "require" or prefer using a Value type in my case rather than sticking with the direct reference type required, is because a struct is being used as a Dictionary's key, and this ...
1
vote
0
answers
23
views
Nullable Value Types as Members in a Struct: What are the Implications Memory-Wise? [duplicate]
I'm new to StackOverflow so sorry if anything about this post is weird or poorly formatted, giving it my best here, I'm also infamously bad with programming linguo so I might sound incredibly dumb as ...
1
vote
1
answer
406
views
What really happens "behind the scenes" when you copy a struct?
In Swift, the Struct is a value type, while the Class is a reference type. So, two different variables cannot point to the same underlying struct instance, while they can point to the same instance ...
0
votes
1
answer
169
views
Does any built-in value type in C# implement any interface?
I'm studying Boxing in C#. And it says if a value type such as a struct implements an interface, there is a boxing operation when we assign an object of type struct to a variable of the type of the ...
2
votes
2
answers
191
views
In Clojure, is there a meaningful difference between value types and reference types?
I'm starting to realise that there is little distinction between value types and reference types if both are immutable. To test this, I wanted to see how a true lover of immutability like Clojure ...
2
votes
1
answer
889
views
Are Kotlin data classes Value types or Reference type?
I am from Swift background. Swift has both "value" type & "reference" type support, I am bit curious. Does Kotlin have similar concepts?
By default, any class is a reference ...
-1
votes
1
answer
100
views
Making value-type arrays in c# [closed]
I'm transfering data between c++ and c# and I really need to have value-type arrays or list to pass the data directly. I don't mind them being a const expression. Is there a way to have an array which ...
-2
votes
1
answer
39
views
Why setting ParticleSystem.main properties works like this?
In Unity manual we are told to set properties like this
ParticleSystem ps = GetComponent<ParticleSystem>();
var main = ps.main;
main.startDelay = 5.0f;
And I cannot understand, why it works, as ...