locked
Declaring Property in ASP.NET 4.0 on VB RRS feed

  • Question

  • User-2089506584 posted

    Hi,

    I haven't check yet all the new features of ASP.NET 4.0 but I'm wondering if one of those features (VB syntax) is declaration of class properties oppose to C# in less code.

    VB.NET (18 lines)
        Private _FirstName As String
        Public Property FirstName() As String
            Get
                Return _FirstName
            End Get
            Set(ByVal value As String)
                _FirstName = value
            End Set
        End Property

        Private _LastName As String
        Public Property LastName() As String
            Get
                Return _LastName
            End Get
            Set(ByVal value As String)
                _LastName = value
            End Set
        End Property

    C# (2 lines)
    public string FirstName{ get; set; }
    public string LastName{ get; set; }


    cheers,

    imperialx

    Wednesday, September 2, 2009 3:56 AM

Answers

  • User-720791821 posted

    You may not be using the new version of it.

    check the link

    http://raminassar.dubaidev.net/post/2009/06/25/VBNET-10-New-Features-Auto-Implemented-Properties.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 2, 2009 7:33 AM

All replies

  • User-720791821 posted

    http://blogs.msdn.com/wriju/archive/2009/06/02/vb-net-10-automatic-property.aspx

    Wednesday, September 2, 2009 4:25 AM
  • User312496708 posted

    In VB now you will be able create the same property with below mentioned syntax

    Public Property FirstName As String

    Public Property LastName As String

    Wednesday, September 2, 2009 4:28 AM
  • User-2089506584 posted

    Public Property FirstName As String

    But I get this error "Property without a 'ReadOnly' or 'WriteOnly' specifier must provide both a 'Get' and a 'Set'."


    Wednesday, September 2, 2009 7:15 AM
  • User-720791821 posted

    You may not be using the new version of it.

    check the link

    http://raminassar.dubaidev.net/post/2009/06/25/VBNET-10-New-Features-Auto-Implemented-Properties.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 2, 2009 7:33 AM