Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:43:46+00:00 2026-05-31T08:43:46+00:00

This is first way: Public Class MyClass Private _Property As String Property Property ()

  • 0

This is first way:

Public Class MyClass
     Private _Property As String

     Property Property () As String
         Get
             Return _Property 
         End Get
         Set(ByVal Value As String)
             _Property = Value
         End Set
     End Property

    Public Function DoSomething() As String
        Return _Property & Now()
    End Function  
End Class

Also I can do it in this way:

Public Class MyClass

    Public Property As String

    Public Function DoSomething() As String
        Return Property & Now()
    End Function  

End Class

Which way is preferred?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:43:47+00:00Added an answer on May 31, 2026 at 8:43 am

    The shorter way is preferred (by me) because it’s easier to read and understand. You can always switch to a fully written property definition if you need to do something special.

    Some remarks though.

    You should always use the property getter (Property) inside your code. Never use the internal variable (_Property). This is important because this way all interaction with that internal variable goes through a single point which you can than easily modify. Perhaps you want to format the property or throw an exception when the value is incorrect, etc. So the DoSomething function should be exactly the same in both methods.

    Public Function DoSomething() As String
      Return Me.Property & Now()
    End Function  
    

    Finally the Property shorthand is incorrect. It should be:

    Public Property [Property] as String
    

    You didn’t give it a name. I assume you want to name it ‘Property’. I assume this is a reserved word and thus you probably would run into issues. By declaring it like this the compiler won’t trip over it. But you’d be wise to avoid reserved words in your class & method names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following class: public class MyClass { private string _param; public MyClass ()
I have a simple class like this: public class myClass { public List<string> innerList;
Let's get this out of the way first: I know that SessionFactory is immutable
I have the following object: public class MyClass { public int Id { get;
I have a class in C# like this: public MyClass { public void Start()
In java <1.5, constants would be implemented like this public class MyClass { public
Why does this return an error? public class Class1 { public enum MyEnum {
This is the first time I have manipulated hashes and arrays in this way
Using Dozer to map two objects, I have: /** /* This first class uses
#include <iostream> using namespace std; // This first class contains a vector and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.