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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:39:39+00:00 2026-05-11T17:39:39+00:00

And if so, why? and what constitutes long running? Doing magic in a property

  • 0

And if so, why?
and what constitutes “long running”?

Doing magic in a property accessor seems like my prerogative as a class designer. I always thought that is why the designers of C# put those things in there – so I could do what I want.

Of course it’s good practice to minimize surprises for users of a class, and so embedding truly long running things – eg, a 10-minute monte carlo analysis – in a method makes sense.

But suppose a prop accessor requires a db read. I already have the db connection open. Would db access code be “acceptable”, within the normal expectations, in a property accessor?

  • 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-11T17:39:39+00:00Added an answer on May 11, 2026 at 5:39 pm

    Like you mentioned, it’s a surprise for the user of the class. People are used to being able to do things like this with properties (contrived example follows:)

    foreach (var item in bunchOfItems)
        foreach (var slot in someCollection)
            slot.Value = item.Value;
    

    This looks very natural, but if item.Value actually is hitting the database every time you access it, it would be a minor disaster, and should be written in a fashion equivalent to this:

    foreach (var item in bunchOfItems)
    {
       var temp = item.Value;
       foreach (var slot in someCollection)
          slot.Value = temp;
    }
    

    Please help steer people using your code away from hidden dangers like this, and put slow things in methods so people know that they’re slow.

    There are some exceptions, of course. Lazy-loading is fine as long as the lazy load isn’t going to take some insanely long amount of time, and sometimes making things properties is really useful for reflection- and data-binding-related reasons, so maybe you’ll want to bend this rule. But there’s not much sense in violating the convention and violating people’s expectations without some specific reason for doing so.

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

Sidebar

Related Questions

What is the difference between A simple fields-accesors-mutators class A rich-modeled class What constitutes
Which constitutes better object oriented design? Class User { id {get;set} } Class Office
Our project constitutes of many modules (e.g. a HR management system containing modules like
After reading Wolfbyte's answer on Enterprise FizzBuzz I have thought about what constitutes a
I have content on a portable HDD that is to be shared between 2
In other words, what technology would take care of doing the time tracking? Would
I'm working on a plug-in to one of our products (an RMS) that will
I'm interested in what constitutes a big team and what ratio of developers, Architects,
If I use an lgpl licensed javascript library, do I have to release my
Background My board incorporates an STM32 microcontroller with an SD/MMC card on SPI and

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.