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

 
Participant
7 months, 4 weeks ago.

  • Author
    Posts
  • #96644

    Participant
    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

    Participant
    Points: 151
    Helping Hand
    Rank: Participant

    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.

    https://msdn.microsoft.com/en-us/library/system.stringcomparer(v=vs.110).aspx

  • #97019

    Participant
    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.