2

In vb.net I've this code block:

Public Sub AddItem(Text As String, Optional Left As Integer = 0, Optional Header As Boolean = False)
    Dim Item As ListItem
    ReDim Item.Text(0)
    Item.Text(0).Text = Text
    Item.Text(0).Left = Left
    Item.Header = Header
    LstItems.Add(Item)
End Sub

UPDATE: ListItem

Public Structure ListItem
    Dim Text() As ListText
    Dim Header As Boolean
End Structure

this code allow me to add an item to a list, ReDim allocate the storage space for an array variable in vb.net, in c# what is the equivalent of this code? I also tried to convert it on converter.telerik.com without success.

Dillinger
  • 1,823
  • 4
  • 33
  • 78

1 Answers1

1
ReDim Item.Text(0)

in VB is the same as

Item.Text = new String[1];

in C#. But you might want to take a step back here and ask what the program is actually doing, and then write a more idiomatic C# program. In particular, should Text be a List<string> instead of an array?

Eric Lippert
  • 647,829
  • 179
  • 1,238
  • 2,067