Instantiate a generic collection with ctor args

This topic contains 2 replies, has 2 voices, and was last updated by  Ritmo2k 1 month, 4 weeks ago.

  • Author
  • #96644


    How does one create a HashSet with a ctor arg of StringComparison.OrdinalIgnorecase?

    PS M:\> New-Object -TypeName System.Collections.Generic.HashSet[string] -ArgumentList @([StringComparison]::OrdinalIgnorecase)
    New-Object : Multiple ambiguous overloads found for "HashSet`1" and the argument count: "1".
    At line:1 char:1
    + New-Object -TypeName System.Collections.Generic.HashSet[string] -ArgumentList @( ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException
        + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
  • #96758

    Fredrik Kacsmarck

    Might be wrong (don't read MSDN all day 🙂 ) but if I understand it correctly StringComparison is a enum/property to tell string methods how to compare strings.
    It's not a constructor.

    The class and constructor is StringComparer.

  • #97019


    I tried to reply when you posted your response (thanks for doing that so quickly) but the broken web host dos prevention locked me out...

    I can't believe I fat fingered that without noticing, I actually fired up VS and whipped up a simple invocation as I thought I wasn't doing something right. I still failed to notice my console repro was differnt:)

    Thanks for the nudge!

You must be logged in to reply to this topic.