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 8896839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:10:49+00:00 2026-06-15T00:10:49+00:00

I read a zillion articles on Auto Properties and can’t come up with a

  • 0

I read a zillion articles on Auto Properties and can’t come up with a reason for NOT doing something like the following example. Am I missing something here; i.e. is there any reason I should use regular properties in this example? I do it regularly and it works fine.

In a different thread here on StackOverflow ( C#3.0 Automatic properties with extra logic ) the answer was declared to be No as in “No, automatically implemented properties have no declared implementation. Any extended implementation that you wish to provide would have to use a regular property.”

    class Foobar
{
    public string Description { get; set; }
    public bool Scary { get; private set; }

    public void Describe(int size)
    {
        if (size <= 3)
        {
            switch (size)
            {
                case 1:
                    Description = "Cute";
                    Scary = false;
                    break;
                case 2:
                    Description = "Interesting";
                    Scary = false;
                    break;
                case 3:
                    Description = "Interesting";
                    Scary = false;
                    break;
            }                
        }
        else if (size > 4 && size < 10)
        {
            Description = "I'm sweating!";
            Scary = true;
        }
        else
        {
            Description = "I'm outta here - every man for himself";
            Scary = true;
        }
    }
}
  • 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-06-15T00:10:50+00:00Added an answer on June 15, 2026 at 12:10 am

    You’re not adding code to the get/set methods for your properties, you’re adding an entirely separate method to the class which uses the get/set properties.

    If someone uses the set methods for Description or Scary directly, rather than using Describe, no custom logic is executed. As an example, nothing prevents someone from doing: obj.Describe(10); obj.Description = "Cute";. If you overloaded the set method for those properties you could prevent someone from creating such a cute and scary object.

    The answer in the question that you’ve linked to is perfectly correct; you cannot add validation to the get/set methods of an auto-implemented property; if you want to you need to explicitly define the get/set methods.

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

Sidebar

Related Questions

Read that the following code is an example of unsafe construction as it allows
Having read the documentation and many many articles I believe the following should work
Read the entire file of 500-600 MB I can not, since the data are
Read on before you say this is a duplicate, it's not. (as far as
Read about the z-index issue and tried anything, but just can't seem to fix
read, write, error = select.select(sockets, sockets, sockets, 60.0) What is recommended if something ends
I read a couple of articles about using antiforgery token in forms to prevent
Read some other things on here re: this similar problem but am not sure
Having read this past question for git, I would like to ask if there
Read this question carefully because I am not asking how to get rid of

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.