Need help converting from c# to .net???
Hi guys
I have never done c# before in my life and i have found some example code that i need for a project, but it is written in c#!!! :confused: So i was wondering if anybody could help me....i have tried a couple of c# to vb converters but what i get bak confuses me even more! :(
Here's the c# code i have:
Code:
Private List<Viewport3D> _slaves;
public List<Viewport3D> Slaves
{
get
{
if (_slaves == null)
_slaves = new List<Viewport3D>();
return _slaves;
}
set
{
_slaves = value;
}
}
Thanks in advance for any help
:afrog:
P.S Am using .net 3.0
Re: Need help converting from c# to .net???
That is a property declaration for a property named Slaves that is a generic List of ViewPort3D objects. The getter tests the _slaves variable to see if it is a null reference and, if it is, creates a new List. It then returns the _slaves variable. The setter simply assigns the new value to the _slaves variable. Now that you know what the code does you can write your own VB code. It's pretty standard stuff for a property declaration.
Having said that, it is rather abnormal to have a setter for a collection property. You would normally make a property like that read-only.
Re: Need help converting from c# to .net???
Oh....i didn't realise it was a property declaration.
Thanks for your help, i should be able to convert it from here.
Thanks again. :thumb:
:wave:
Re: Need help converting from c# to .net???
The reason you get garbage back from the online converters is that they (still) don't handle generics. Try using the trial/demo version of any commercial C# to VB converter instead.
The equivalent VB code is:
VB Code:
Private Private _slaves As List(Of Viewport3D)
Public Property Slaves() As List(Of Viewport3D)
Get
If _slaves Is Nothing Then
_slaves = New List(Of Viewport3D)()
End If
Return _slaves
End Get
Set
_slaves = Value
End Set
End Property