No. The initialization syntax for Dictionary<TKey,TValue>
is C# syntax candy. Powershell has its own initializer syntax support for System.Collections.HashTable
(@{}
):
$drivers = @{"nitrous"="vx"; "directx"="vd"; "openGL"="vo"};
For [probably] nearly all cases it will work just as well as Dictionary<TKey,TValue>
. If you really need Dictionary<TKey,TValue>
for some reason, you could make a function that takes a HashTable
and iterates through the keys and values to add them to a new Dictionary<TKey,TValue>
.
The C# initializer syntax isn't exactly "direct" anyway. The compiler generates calls to Add()
from it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…