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.
583
questions
-2
votes
1
answer
28
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 ...
1
vote
2
answers
44
views
c++ template template syntax: simplicity vs useability why not 'auto'
first code below compiled fine after sweating with the word 'class' five times
in one line, and definition in "main" of shelf<std::vector, int> top_shelf;
looks too fragmented to me, ...
0
votes
3
answers
48
views
Copying delegates behavior
C# 11:
file class C
{
public int IntField1;
}
file struct S
{
public int IntField1;
}
file class StructureVsClassWhenCopying
{
private static void v1()
{
System.Console....
0
votes
2
answers
87
views
How do I identify whether a column entry starts with a letter or a number using m code in power query?
I have a column that contains either letters or numbers. I want to add a column identifying whether each cell contains a letter or a number. The problem is that there are thousands of records in this ...
0
votes
2
answers
43
views
A 2-in-1 check existence and store - is this possible when searching a Dictionary?
A common pattern I like to use in C# is one where instead of first checking whether something exists in a collection with Any then finding it again with First, I simply call FirstOrDefault, which both ...
0
votes
1
answer
18
views
Generic nullable reference and value type parameters the same? [duplicate]
The compilers tells me that the following two methods have the same signature:
internal static void Foo<T>(T? output) where T : class
{}
internal static void Foo<T>(T output) where T : ...
0
votes
0
answers
56
views
Nullable parameters in a generic class
I know similar questions have been asked already but I did not find any solution for my particular issue.
I have a generic class with a constructor like this:
public ClampedValue(T value, T? min = ...
0
votes
1
answer
37
views
Comparing lists of ints in, while considering two ints not to be equal if repeated
I know this question has been reiterated multiple times, and I think this is straightforward when using lists of reference types. That is also what most questions talk about. When doing this with ...
0
votes
0
answers
13
views
Struct mutation & memory management
I know structs are made for the purpose of being immutable but I don’t quietly understand the concept of “when we change a property in struct, the whole struct gets destroyed and created again” so now ...
1
vote
0
answers
130
views
Why doesn't Project Valhalla introduce mutable structs?
Looks to me like primitive classes could behave more efficiently (at reasonable sizes) if they weren't immutable as currently proposed, but worked more like C structs.
Given this primitive class
...
0
votes
2
answers
408
views
Are Structs with Struct-Arrays value or reference-based?
If I have a Struct with arrays of other structs, is this than still a value-based type? In detail what I don´t understand is, that usually structs are meant to be value-based, but arrays for example ...
-1
votes
2
answers
70
views
Swift value type did not copy on first assignment?
The example in official document explain value type as this that the copy operation will occurred in assignment:
// Value type example
struct S { var data: Int = -1 }
var a = S()
var b = a ...
1
vote
2
answers
53
views
converting ValueType to BigInteger threw exception: System.InvalidCastException: Specified cast is not valid
Following the MSDN example of
ValueType Class on this lines
// Use BigInteger as common integral type
if (IsInteger(value1) && IsInteger(value2)) {
BigInteger bigint1 = (BigInteger) ...
0
votes
0
answers
28
views
When ARC gets called for value types like struct and enums in Swift?
I have basic question about allocating memory for the value types.
If any value type is not used in the classes, functions or closures, how memory gets allocated for these value types lie struct or ...
0
votes
0
answers
58
views
How swift know value of memory is address or actual value that I assigned
struct ValueType {
var member: Int
}
class ReferenceType {
var member: Int
init(member: Int) {
self.member = member
}
}
var valueTypeObject = ValueType(member: 3)
var ...
1
vote
1
answer
71
views
Why we can apply == (Equality Operator) on value type(like int) in C#?
Equality operator (==) is a reference type and we all know that Int32 is a struct which means that is a value type. I also checked the inside of the Int32 and I couldn't find any Operator Overloading ...
0
votes
0
answers
36
views
Best and most efficient way to differentiate and assign types to timestamp tokens
I am working on timestamps parsing. The tokenization of the timestamps is being handled with python using the spacy library. Then I am sending over the tokens from python to Java. What I am trying to ...
-2
votes
1
answer
36
views
How to pass a ValueType arg to a Method in C# reflection?
My question is that a method requires a long type arg and i want to execute it by reflection. However, MethodInfo needs a array of object and long is a value type, it cannot be cast to object.
How to ...
-1
votes
2
answers
169
views
How to create a value typed Struct with strings?
I want to read a MemoryMappedFile with a struct. Strings are located in this file. So I created a struct like this:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct ...
3
votes
2
answers
502
views
Returning Span from a Property With Unsafe and Fixed
I came across something very much like the below at work. I have never worked with a C# codebase that makes such heavy use of structs before.
I have used fixed before to prevent the garbage collector ...
0
votes
2
answers
592
views
Datatables.net and asp.net core WebApi get search[value]
I'm trying to figure out server-side processing in Datatables.net with an asp.net core WebApi-Controller.
DT is sending an http-get to the controller with some given parameters as described here:
...
0
votes
1
answer
244
views
Why can't I update the value of a string in an extension method? [duplicate]
I'm trying to create an extension method to simplify a small bit of code that I use a lot:
var test = "this is a test.";
var substring = test.Substring(0, 4);
test = test.Remove(0, 4).Trim();...
-1
votes
1
answer
205
views
C# Reference Type alternatives to Value Types [closed]
I know there are different posts related to questions around this topic, but I couldn't find any source on the question I have.
In some scenarios, it would be much easier, if value types behaved as ...
1
vote
2
answers
129
views
C++ : rebind variable of generic type
Re-use heap memory for generic types by rebinding variables.
What I want to do:
template <typename T> //unconstrained type
//...
{
//in some complex procedural logic
T rebindable = .../*r-...
5
votes
1
answer
773
views
Why the return value of ValueTuple is empty JSON?
In .NET 5, I created a default webapi solution "WebApplication1", and I have an action in WeatherForecastController:
[HttpGet]
[Route("[action]")]
public (...
-1
votes
1
answer
329
views
Why "int" is not a class like "String"?
I know this is a weird question and maybe a little vague. Because I myself isn't sure about what I'm really missing. But please hear me out.
In java, there are :
value types (like int, char, ...).
...
2
votes
1
answer
286
views
Method return default value
Why am I allowed to return null within a method declaration, which could also return a value type?
I thought interfaces such as IList<T> have no restriction on the type of their implementation.
...
-1
votes
1
answer
335
views
Where are static structs stored in C#?
From this question I understood that
structs can be allocated on the stack or in registers and not on the heap
if a struct is part of a reference type object on the heap, the struct will also be on ...
3
votes
2
answers
455
views
Setting dictionary tuple values directly
Is it possible to do something similar to this: dictTupleTest[key].Item1 = toggle; in the following situation?
Dictionary<int, (bool, bool)> dictTupleTest = new Dictionary<int, (bool, bool)&...
2
votes
0
answers
386
views
How do Swift allocates in memory value-type that conforms to protocol
I was thinking of how do Swift allocates in memory value-type objects like structs, enums etc that conforms to some protocol. Like I always thought - types that conforms to some protocol should have ...
1
vote
1
answer
75
views
How does .Net understand nested valuetypes? Are they valuetypes?
In situations like this:
public struct SectorLocator
{
public Surface Side { get; init; } //this is an enum-int
public VerticalPortion Section { get; init; } //this is another enum-int
}
...
1
vote
1
answer
82
views
Generate Struct Value in Get Accessor
TL:DR; is it bad to make a struct where the value does something to initialize itself at the beginning of get for the struct itself (no public properties, but any comparison/etc. executes ...
1
vote
1
answer
185
views
Is there a way to check if a delegate is a value or a reference type?
Lets say we had something like this:
protocol Delegate {}
struct Value: Delegate {}
class Reference: Delegate {}
struct Test {
let delegate: Delegate
}
How could we know if a delegate is a ...
-1
votes
1
answer
87
views
What is the difference for fields vs properties which construct (immutable) value types in C#? [duplicate]
Example:
public readonly struct Vector3
{
public readonly float x;
public readonly float y;
public readonly float z;
public Vector3(float x, float y, float z)
{
this.x = x;...
-1
votes
3
answers
437
views
Assign value of a reference property to a variable
I have a scenario where I want to pass in a reference of the value type bool (value type marked with ref) to a constructor of an other class and want to update its value in the other class. Something ...
2
votes
1
answer
219
views
Recursive bezier curve algorithm not working in C#
I copied the exact algorithm in this post but somehow it's not working in C# Recursive function of Bezier Curve python. Here's my code:
private static Vector2 GetPointByInterpolation(List<...
2
votes
1
answer
127
views
How to create custom value types in OData?
I have an OData API and was wondering what is the proper way of adding support for a custom value-type/strong type object so that it is recognized during serialziation, desserialization and metadata-...
3
votes
1
answer
1k
views
Swift: how closure captures variables of value type?
Take a look at the following code snippet
struct Person{
var name: String
let surname: String
var closure: (()->())?
init(name: String, surname: String){
self.name = name
self....
0
votes
1
answer
269
views
Sparx Enterprise Architect SysML: can you make composite value types?
Sparx Enterprise Architect / SysML:
Can you make composite value types? Like composite blocks?
I wanted to design in a visual way (tree form) data types that are composed of values, where the latter ...
1
vote
1
answer
121
views
Weird memory behaviour with array of structs
I am seeing a very weird (or at least weird to me) behaviour regarding memory addresses when playing around with structs in Swift.
I have the following code in a Playground:
func address(o: ...
2
votes
2
answers
170
views
Can I treat a reference type as a value type here, or do I need to clone?
Consider the following method:
public (MySpecialType one, MySpecialType two) ReturnTwoSeparateObjects()
{
MySpecialType before = new MySpecialType();
MySpecialType after = before;
after....
0
votes
1
answer
117
views
Why there are no allocations with AnyVal and generics in Scala
I have an unexpected result with a benchmark.
The aim of this benchmark is to illustrate that Scala AnyVal doesn't play well with generics. I've created a type AnyValId that extends AnyVal.
The ...
0
votes
1
answer
304
views
Memento pattern issues in c#
I'm struggling to figure out an issue with the Memento pattern. Although I understand it and I'm able to implement it, I must be missing something because it seems to me that if fails when applied to ...
-3
votes
1
answer
941
views
If string is reference type in C#, why does passing a string argument behaves as value type? [duplicate]
I'm confused by the following. If string is a reference type in C# and gets passed as a reference type, why doesn't changing the parameter value inside the method lead to change of value in the ...
2
votes
1
answer
398
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 ...
2
votes
1
answer
180
views
ECMA CLI spec: initobj instruction description for value types
The ECMA CLI spec has the following statement in the description for the initobj CLI instruction:
"If typeTok is a value type, then after this instruction is executed, the instance is ready for a ...
0
votes
0
answers
54
views
Consequences of changing a value (struct) type to a reference (class) type [duplicate]
Consider a struct type defined as follows:
public struct Device
{
public string Name {get; set;}
public string Data {get; set;}
public void UploadData(DataSource source)
{
...
0
votes
1
answer
133
views
Making value type variables nullable by using "?": does it imply boxing?
Given the following assumptions in C#:
boxing and unboxing let me convert any value type variable to an object type, which is a reference type (therefore it's also nullable), like in the example:
...
1
vote
0
answers
175
views
Let class only contain value type fields
What I want to achieve:
A container which contains a bunches of value type fields.
The container has the following characteristics
Acts like POD.
Mutable
Could be copied by value.
Fields of the ...
0
votes
2
answers
96
views
How to justify Strings in java as reference type? check out the following cases
Case 1:
String s1 = "Hello";
String s2 = s1; //now has the same reference as s1 right?
System.out.println(s1); //prints Hello
System.out.println(s2); //prints Hello
...