Results 1 to 4 of 4

Thread: Need help converting from c# to .net???

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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#!!! 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


    P.S Am using .net 3.0
    Last edited by Kimmy4; Feb 2nd, 2007 at 05:10 AM.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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.

    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    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:
    1. Private Private _slaves As List(Of Viewport3D)
    2.  
    3. Public Property Slaves() As List(Of Viewport3D)
    4.    Get
    5.       If _slaves Is Nothing Then
    6.           _slaves = New List(Of Viewport3D)()
    7.       End If
    8.  
    9.           Return _slaves
    10.    End Get
    11.    Set
    12.          _slaves = Value
    13.    End Set
    14. End Property
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width