dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
725 stars 1.56k forks source link

Documentation Issue: ConditionalWeakTable<TKey,TValue> Class #10344

Open briangithex opened 2 months ago

briangithex commented 2 months ago

Type of issue

Code doesn't work

Description

1) The provided C# example fails to compile due to a conversion error. Example fixes: A) Replace cwt.TryGetValue(wr2.Target, out data) with cwt.TryGetValue((ManagedClass)wr2.Target, out data) B) Replace var cwt = new ConditionalWeakTable<ManagedClass, ClassData>(); with var cwt = new ConditionalWeakTable<object, ClassData>();

2) Possibly it's worth adding a note that the example may fail to function in debug mode, since in-scope variables are ineligible for collection during debug.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.conditionalweaktable-2?view=net-8.0&redirectedfrom=MSDN

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Runtime.CompilerServices/ConditionalWeakTable`2.xml

Document Version Independent Id

6a9b0e31-d0a6-c930-7959-20ac6f03ec4a

Article author

@dotnet-bot