I know I can add to an [Ordered] hash table at a particular index, with
$ordered.Insert([Int], [String], [String])
and I can set the value at a certain index with
$ordered[[Int]] =
And that leads me to THINK that I should also be able to GET the index of a given key. It seems that direct access isn't possible, as there in no .IndexOf() method. But I know I can get an array of the keys, and an array does have .IndexOf(), but that then returns another array, of -1 for the non matches and 0 for the matches.
So
$ordered = [Ordered]@{
'one' = 1
'two' = 2
'three' = 3
'four' = 4
}
$ordered
$ordered.Keys.IndexOf('two')
produces
Name Value
---- -----
one 1
two 2
three 3
four 4
-1
0
-1
-1
So now I need to get the index of that 0. So that doesn't seem to be the way to do it. I also found this. And indeed this works.
[Array]::IndexOf($ordered.Keys,'three')
But it has me wondering, is there a way to make the previous approach work? $ordered.Keys.IndexOf([String]) just seems like it should be viable, and I am just missing how to extract only the successful match. But perhaps not, and the static method is the way to go?
OrderedDictionaryKeyValueCollectionimplementsIListso,$ordered[$ordered.Keys.IndexOf('two')]works perfectly fine. In .NET Framework a bit more work is needed tho, I'm surprised you have a real use case for this. Why not explain what you're trying to accomplish as there is likely a better way to do it$ordered[$ordered.Keys.IndexOf('two')]than doing just this$ordered['two']or$ordered.ContainsKey('two')for validation ? Maybe If you can add a reproducible example of your problem we may be able to help you find the best solution to the problem, I know what you have right now is a reproducible example but I think the solution you're looking for is reinventing the wheel in this case{AD211D5C-0BFF-3956-8998-C5C1F8FB5884}key and some rubbish data is found in{28B89EEF-6100-0409-2102-CF3F3A09B77D}. In my log I want the correct log info+ X64 {AD211D5C-0BFF-3956-8998-C5C1F8FB5884}: Autodesk Civil 3D 2023 - English (13.5.211.0) [ADSK GUID ODIS (ADSK GUID NULL)]to be immediately followed by the bogus log item, despite the fact that it was actually processed first.