Instantiate a generic collection with ctor args

Welcome Forums General PowerShell Q&A Instantiate a generic collection with ctor args

This topic contains 2 replies, has 2 voices, and was last updated by

10 months, 4 weeks ago.

  • Author
  • #96644

    Points: 1
    Rank: Member

    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

    Points: 305
    Helping Hand
    Rank: Contributor

    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

    Points: 1
    Rank: Member

    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!

The topic ‘Instantiate a generic collection with ctor args’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort