tags:

views:

218

answers:

3

I have a DependencyObject in C# that is used in an array. Example shown below:

private KeywordTag[] tags = new KeywordTag[] {
    new KeywordTag { Tag = "test", IncidenceCount = 2076 },
    new KeywordTag { Tag = "oi", IncidenceCount = 2052 },
    new KeywordTag { Tag = "hmm", IncidenceCount = 1887 },
    new KeywordTag { Tag = "grr", IncidenceCount = 1414 },
    new KeywordTag { Tag = "thanks", IncidenceCount = 1166 }}

How would I convert this code to VB.NET?

Thanks!

+2  A: 

Something like:

Private tags() As KeywordTag = { New KeywordTag { Tag = "test", IncidenceCount = 2076 }, New KeywordTag { Tag = "oi", IncidenceCount = 2052 }, New KeywordTag { Tag = "hmm", IncidenceCount = 1887 }, New KeywordTag { Tag = "grr", IncidenceCount = 1414 }, New KeywordTag { Tag = "thanks", IncidenceCount = 1166 }}
Steven Robbins
A: 

Okay, that doesn't seem to work. Fails on the second { bracket.

Luke
Sorry, I didn't actually build it. I'm not sure if there is a direct translation actually, you might have to add a constructor to KeywordTag and pass it in that way.
Steven Robbins
nope, see my response.
Tom Anderson
+3  A: 

dummy's response was almost right, VB.Net's syntax has a "WITH" after the constructors.

Private tags() As KeywordTag = { _
    New KeywordTag() WITH {.Tag = test", .IncidentCount = 2076}, _
    New KeywordTag() WITH {.Tag = "oi", .IncidentCount = 2052}, _
    New KeywordTag() WITH {.Tag = "hmm", .IncidentCount = 1887}, _
    New KeywordTag() WITH {.Tag = "grr", .IncidentCount = 1414}, _
    New KeywordTag() WITH {.Tag = "thanks", .IncidentCount = 1166} _
    }
Tom Anderson
I bet there is not blank before "Tag". But this look better the mine, so i deleted it.
dummy