Deconstruction is referring to the task of splitting structures into multiple separate variables. For questions about destructors, which typically are the opposite of constructors, use the destructor tag.
Questions tagged [deconstructor]
16 questions
3
votes
3 answers
How to convert tuple list to list tuple?
For example, I have an IEnumerable<(int, char)> list. How to convert list into (IEnumerable, IEnumerable)?
Is there a fast way to do this? It would be better to work with System.Linq.

BrandonStudio
- 97
- 7
3
votes
1 answer
Deconstructors and nullable reference types
I have a class with the deconstructor:
public void Deconstruct(out bool isSuccess, out TSuccess? value, out Error? error) {...}
Value of isSuccess defines whish of value or error is null.
Can I somehow let compiler know about this, so when I…

Pavel Voronin
- 13,503
- 7
- 71
- 137
2
votes
1 answer
Does Swift support deconstruction of custom types to tuples?
C# has a neat feature where you can decorate your custom types with deconstruction to allow them to automatically deconstruct to tuples.
Take this class...
public class Person {
public string FirstName { get; set; }
public string LastName …

Mark A. Donohoe
- 28,442
- 25
- 137
- 286
1
vote
1 answer
Do c# class deconstructors delete/destroy the class from memory?
Im reading about c# 10 and read
"A deconstructor (also called a deconstructing method) acts as an approximate
opposite to a constructor: whereas a constructor typically takes a set of values (as
parameters) and assigns them to fields, a…

Mufasatheking
- 387
- 2
- 6
- 16
1
vote
0 answers
Does the destructor get called when a C++ temporary object is destroyed? Why does this code only output three "deconstruction" messages?
class demo{
private:
int x;
public:
demo(int t):x(t) {cout<<"constructor"<

Mark_Jing
- 11
- 2
1
vote
0 answers
c# Inline tupel deconstruction into method args similar to JS's ... operator
In my c# project a method returns a tuple. Is it possible to deconstruct the result of this method immediately inline and use it as arguments for another method call? I imagine something similar to the ... operator in JavaScript.
public (string a,…

André Reichelt
- 1,484
- 18
- 52
0
votes
0 answers
Why does tuple deconstruction return nullable types in C#?
Consider the following C# code:
var info = ("A", "B");
if (info is var (a, b))
{
Console.WriteLine("X = {0}", a);
}
For some reason, the type of the a variable is inferred as optional (string?), while neither the whole tuple nor its elements…

Impworks
- 2,647
- 3
- 25
- 53
0
votes
2 answers
deconstructing an object in react gives another object with a key of 0
I have an array of objects and I'm trying to pass all the values of one element from that array as prop to a child component:
const ParentComponent = () => {
const [selectedBillNumber,setSelectedBillNumber] = useState(2);
const data = [
…

Daniel_Kamel
- 610
- 8
- 29
0
votes
0 answers
React does not update nested state using my setter
I'd like to update a react state (the "app" variable) object dynamically. The state has several properties, one of them is a nested object ("app.error" object). There is a kind of setter function ("setAppData") which takes any number of [existing…

Peter
- 13
- 4
0
votes
1 answer
What composition of rules make the constructor public Point (double x, double y) => (X, Y) = (x, y) valid?
The constructor public Point (double x, double y) => (X, Y) = (x, y); is obviously valid. But what composition of rules makes it so? It's obviously some combo of tuples, lambdas, and deconstructors, but I don't know exactly what step appears where.…

J. Mini
- 1,868
- 1
- 9
- 38
0
votes
0 answers
why does the destructor get called c++
Please explain to me why the destructor gets called on the "strand" object after its assigned with "tari" members. this question has been puzzling me and I haven't been able to move on from it as it gives me the wrong answer of 5 at the end instead…

dlamini2times
- 1
- 1
0
votes
1 answer
How to make a Deconstructor for class that implements IEnumerable
I have a class that implements IEnumerable. It contains a GetEnumerator() method and a private class that implements IEnumerator. The Current() method of that class returns an object that is a KeyValuePair, i.e (some code elided for…

Plunder Bunny
- 87
- 6
0
votes
0 answers
C# record deconstruction
One cool feature with C# record, is the ability to deconstruct them based on their default constructor without having to define your own Deconstruct method.
public record Foo(int Bar, int Baz);
public void Func(Foo foo) {
var (bar, baz) =…

elillesaeter
- 148
- 10
-2
votes
1 answer
Angular how Destructure a object
I received a http response using nano couchdbDB but cannot use .pipe to convert the received data into what actually comes.
myservice.service.ts
export class xx{
public mycall(docid: string = ''){
return nanoInterface.db
…

Kaspacainoombro
- 91
- 6
-3
votes
1 answer
Destructor runs even though object is not deleted?
In my C++ program, I'm working with destructors and constructors in classes. For no apparent reason, when I initiate the constructor, the destructor is also run. This is the function code:
#include "Foo.h"
int main()
{
Foo f;
return…

IcantFind_A_Name
- 1
- 2