#powershell #function PowerShell: Add GetValueOrDefault Method to a Hashtable https://bit.ly/3QwHW0Q via PlanetPowerShell
PowerShell: Add GetValueOrDefault Method to a Hashtable

Enhancing PowerShell with GetValueOrDefault: A Neat Solution for Streamlined Hashtables Have you ever wondered why the Hashtable in .NET lacks a GetValueOrDefault method, a feature readily available i...

DevDojo
@sasstu A very interesting article and I can certainly see the value of such a function since there is no method in #Net While your #powershell code does it well, why not ask the .NET team to add it to #.NET. If you know C#, you might be able to do the PR! but file as an issue asking for it, and demoing the PowerShell code. I'd certainly vote for it. The nanosecond it hit a new version of .NET, it hits the next version of PowerShell (including the next day's bui;d if you are anxious).

@DoctorDNS @sasstu it's already in .NET -- but the #PowerShell team does not enable basic #dotnet functionality if it came out after .NET 2.0 -- so you don't have access to #ExtensionMethods unless you map them into the .NET 1.0 era "ETS"

Here's the method in .NET:
https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.collectionextensions.getvalueordefault?view=net-7.0

Here's the pre-github era feature request:
https://github.com/PowerShell/PowerShell/issues/2226

CollectionExtensions.GetValueOrDefault Method (System.Collections.Generic)

Tries to get the value associated with the specified key in the dictionary.