GoldBishop
GoldBishop

Reputation: 2861

Lambda Expression: CS to VB.Net

I am dumb founded at this statement....maybe its just too many hours/days of doing C# to VB.Net conversion but i am drawing a blank on this conversion.

Any help would be greatly appreciated.

List<string> sColors = new List<string>(this.CustomPaletteValues.Split(','));
try {
   List<Color> colors = sColors.ConvertAll<Color>(s => (Color)(new ColorConverter().ConvertFromString(s)));    

What i have so far:

Dim colors As List(Of Color) = sColors.ConvertAll(Of Color)(....)

As you can see its the content of the lambda that i am hitting a brick wall with.

Upvotes: 3

Views: 557

Answers (3)

Andreas M
Andreas M

Reputation: 11

You can write it in a far more shorter way with implicit typing:

    Dim colors = sColors.ConvertAll(Of Color)(
        Function(s) (New ColorConverter).ConvertFromString(s))

Upvotes: 1

Adam Maras
Adam Maras

Reputation: 26853

Pardon the line breaks, but I believe this is what you want.

Dim colors As List(Of Color) = sColors.ConvertAll(Of Color)(
    Function(s) DirectCast((New ColorConverter).ConvertFromString(s), Color)
)

Upvotes: 1

msarchet
msarchet

Reputation: 15242

sColors.ConvertAll(Of Color)(Function(s) DirectCast(((New ColorConverter).ConvertFromString(s)), Color));

Upvotes: 1

Related Questions