C# version of VB.NET "AddRange" method w/generic collection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dgraper

    C# version of VB.NET "AddRange" method w/generic collection

    Friends:

    I'm an ex-VB programmer with a new job in an all C# shop. No problems
    the past few months thinking/converting between the two, but I just
    ran into a problem translating some working VB code from C#:

    Dim enClr As System.Drawing. KnownColor
    Dim clrs As New System.Collecti ons.Generic.Lis t (Of
    System.Drawing. KnownColor)
    clrs.AddRange(S ystem.Enum.GetV alues (enClr.GetType( )))

    I translated this to:

    System.Drawing. KnownColor enClr;
    System.Collecti ons.Generic.Lis t<System.Drawin g.KnownColorclr s =
    new System.Collecti ons.Generic.Lis t<System.Drawin g.KnownColor>() ;
    clrs.AddRange(S ystem.Enum.GetV alues(enClr.Get Type()));

    But get error on line 3:

    "Argument '1': cannot convert from 'System.Array' to
    'System.Collect ions.Generic.IE numerable<Syste m.Drawing.Known Color>'"

    In the debugger it sure looks likes like
    "System.Enum.Ge tValues(enClr.G etType())" is indeed returning a list of
    type <System.Drawing .KnownColor>. I even ran the code thru a public
    VB.NET to C# converter to see if I was missing anything, it gave me
    exactly the same translation.

    Can anyone see what I'm missing?

    Thanks. - Dave
  • dgraper

    #2
    Re: C# version of VB.NET &quot;AddRange& quot; method w/generic collection

    Martin:

    That was it. Thanks very much!

    And thanks for such a rapid reply. I hope the question wasn't too
    rudimentary. - Dave

    Comment

    Working...