Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where's Deconstruct method of KeyValuePair<> struct?

I'm sure that previously I saw this method, because one year ago I've asked: What is the purpose of Deconstruct method in KeyValuePair<> struct?

But now I simply can't find it, or any trace about it's removal, any questions, nothing.

Compiler agrees:

var s = new KeyValuePair<int, int>(1, 3);
var (x, y) = s;

Error CS1061 'KeyValuePair' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'KeyValuePair' could be found (are you missing a using directive or an assembly reference?

Error CS8129 No suitable 'Deconstruct' instance or extension method was found for type 'KeyValuePair', with 2 out parameters and a void return type.

What's going on?

like image 754
astef Avatar asked Apr 16 '26 08:04

astef


1 Answers

You might be running your code on .NET Framework. Whilst the C# 7 deconstruction syntax is supported in both .NET Framework and .NET Core, the Deconstruct method for KeyValuePair<TKey,TValue> is currently only supported in .NET Core 2.0 and later. You can check the "Applies to" section on Microsoft Docs.

like image 179
Douglas Avatar answered Apr 17 '26 21:04

Douglas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!