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
102
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 ...
114
votes
17
answers
106k
views
What is the difference between a reference type and value type in c#?
Some guy asked me this question couple of months ago and I couldn't explain it in detail. What is the difference between a reference type and a value type in C#?
I know that value types are int, bool,...
106
votes
6
answers
39k
views
AnyObject and Any in Swift
I don't understand when to use AnyObject and when to use Any in Swift.
In my case, I've a Dictionary
[String: ???]
??? : Can be Int, Double, Float, String, Array, Dictionary
Can someone explain me ...
-1
votes
3
answers
91
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&...
2
votes
1
answer
701
views
How to get the actual type of a Swift struct in the disguise of a `__SwiftValue`?
I'm using YapDatabase to encode/decode my Swift value types. After decoding, the type information seems to be lost, that is type(of:element) returns __SwiftValue instead of, e.g., Reservation.
If I ...
42
votes
2
answers
14k
views
Does swift copy on write for all structs?
I know that swift will optimize to copy on write for arrays but will it do this for all structs? For example:
struct Point {
var x:Float = 0
}
var p1 = Point()
var p2 = p1 //p1 and p2 share the ...
6
votes
2
answers
6k
views
"subclassing" generic structs
Is it possible to subclass a generic struct in swift ?
assume we have a struct:
struct Foo<T> {}
and I wana "subclass" it to add some functionality:
struct Something {}
struct Bar<F>:...
0
votes
1
answer
69
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
{
...
0
votes
1
answer
1k
views
Check for null value for value types in VB.NET
I have a KeyValuePair(Of TKey,TValue) and I want to check if it is null or not:
Dim dictionary = new Dictionary(Of Tkey,TValue)
Dim keyValuePair = dictionary.FirstOrDefault(Function(item) item.Key = *...
92
votes
5
answers
6k
views
Boxing Occurrence in C#
I'm trying to collect all of the situations in which boxing occurs in C#:
Converting value type to System.Object type:
struct S { }
object box = new S();
Converting value type to System....
2
votes
3
answers
168
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/...
32
votes
3
answers
12k
views
Why must fixed size buffers (arrays) be declared unsafe?
Let's say I want to have a value type of 7 bytes (or 3 or 777).
I can define it like that:
public struct Buffer71
{
public byte b0;
public byte b1;
public byte b2;
public byte b3;
...
113
votes
7
answers
42k
views
Returning two values, Tuple vs 'out' vs 'struct' [closed]
Consider a function which returns two values. We can write:
// Using out:
string MyFunction(string input, out int count)
// Using Tuple class:
Tuple<string, int> MyFunction(string input)
// ...
19
votes
4
answers
14k
views
In C# , Are Value types mutable or immutable ?
Value types behavior shows that whatever value we are holding cannot be changed through some other variable .
But I still have a confusion in my mind about what i mentioned in the title of this post ...
6
votes
6
answers
1k
views
Is value type boxing when it is a field of reference type?
There is code:
struct A
{
int b;
}
class B
{
A a;
int b;
}
Questions are:
Is a in B boxed or not?
Is a in B located in stack or in heap?
Is b in A boxed or not?
Is b in A stack or in heap?
...