convert from c#

  • Thread starter Thread starter João Santa Bárbara
  • Start date Start date
J

João Santa Bárbara

hi all
how can i change this from C# to VB.NET
thsk
JSB


17: public string this[int index]
18: {
19: get
20: {
21: string tmp;
22:
23: if( index >= 0 && index <= size-1 )
24: tmp = words[index];
25: else
26: tmp = "";
27:
28: return ( tmp );
29: }
30: set
31: {
32: if( index >= 0 && index <= size-1 )
33: words[index] = value;
34: }
35: }
 
* "João Santa Bárbara said:
how can i change this from C# to VB.NET

17: public string this[int index]
18: {
19: get
20: {
21: string tmp;
22:
23: if( index >= 0 && index <= size-1 )
24: tmp = words[index];
25: else
26: tmp = "";
27:
28: return ( tmp );
29: }
30: set
31: {
32: if( index >= 0 && index <= size-1 )
33: words[index] = value;
34: }
35: }

Did you try the converters?

C# -> VB.NET Converters:

<URL:http://www.aspalliance.com/aldotnet/examples/translate.aspx>
<URL:http://www.kamalpatel.net/ConvertCSharp2VB.aspx>
<URL:http://csharpconverter.claritycon.com/>
<URL:http://www.ragingsmurf.com/vbcsharpconverter.aspx>
<URL:http://www.gotdotnet.com/Community/...mpleGuid=c622348b-18a9-47d6-8687-979975d5957d>

<URL:http://www.remotesoft.com/>
-> "Octopus"
 
Hi,


Public Property Myprop(ByVal index As Long) As Long
Get
Dim tmp As String
If index > 0 And index <= size - 1 Then
tmp = words(index)
Else
tmp = ""
End If
Return tmp
End Get
Set(ByVal Value As Long)
If index >= 0 And index <= size - 1 Then
words([index] = Value)
End If
End Set
End Property

Stefano
 
Default Public Property Item(index As Integer) As String
Get
Dim tmp As String
If index >= 0 And index <= (size-1) Then
tmp = words(index)
Else
tmp = ""
End If
Return tmp
End Get
Set(value As String)
If index >= 0 And index <= (size - 1) Then
words(index) = value
End If
End Set
End Property
 
Stupid boy ! As Long and returning a String ????


Stefano Galluzzo said:
Hi,


Public Property Myprop(ByVal index As Long) As Long
Get
Dim tmp As String
If index > 0 And index <= size - 1 Then
tmp = words(index)
Else
tmp = ""
End If
Return tmp
End Get
Set(ByVal Value As Long)
If index >= 0 And index <= size - 1 Then
words([index] = Value)
End If
End Set
End Property

Stefano
João Santa Bárbara said:
hi all
how can i change this from C# to VB.NET
thsk
JSB


17: public string this[int index]
18: {
19: get
20: {
21: string tmp;
22:
23: if( index >= 0 && index <= size-1 )
24: tmp = words[index];
25: else
26: tmp = "";
27:
28: return ( tmp );
29: }
30: set
31: {
32: if( index >= 0 && index <= size-1 )
33: words[index] = value;
34: }
35: }
 
João,
Stafano was close:

Default Public Property Myprop(ByVal index As Integer) As String
Get
If index >= 0 AndAlso index <= size - 1 Then
Return words(index)
Else
Return ""
End If
End Get
Set(ByVal value As String)
If index >= 0 AndAlso index <= size - 1 Then
words(index) = value
End If
End Set
End Property

The "Default" on the property makes it behave more like the indexer. An int
in C# is an Integer in VB.NET, in that they both are aliases to
System.Int32.

I don't see that the tmp in the getter is really doing anything (adding
value), so I removed it.

I would consider throwing an IndexOutOfRangeException or
ArgumentOutOfRangeException in the getter & setter...

Hope this helps
Jay
 
Back
Top