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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:35:04+00:00 2026-05-24T21:35:04+00:00

This is an example I have seen in the Effective C# book: private BindingList<PayrollData>

  • 0

This is an example I have seen in the Effective C# book:

private BindingList<PayrollData> data; 
public IBindingList MyCollection 
{
get { return data; } 
}
public void UpdateData() 
{
// Unreliable operation might fail: 
var temp = UnreliableOperation();
// This operation will only happen if 
// UnreliableOperation does not throw an 
// exception. 
data = temp;
}

The author says this will work for value type and not for reference type.
I couldn’t understand what he meant.

I think I now understand: a collection is a ref type. consumers of “data field” won’t remeber they a re holding a copy to the old storage on the heap.
if “data” was value type – the consumers (other code that uses data) will remeber they are holding a deep copy of data and will ask for it again when need to update.

right ?

  • 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-24T21:35:05+00:00Added an answer on May 24, 2026 at 9:35 pm

    The collection is a reference type, so other holding code onto that will see the old data.

    Two possible solutions:

    Instead of data = temp use data.Clear(); data.AddRange(temp) which will change the contents of the data field.

    Or better delete the MyCollection property and make class implement IEnumerable. This results in much better encapsulation.

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

Sidebar

Related Questions

For example i have this xml. I need to get value of parameter val
I have seen this example: http://jsfiddle.net/UwEe2/306/ that is implemented with scrollleft . Now I
I have picked up this example which converts BitSet to Byte array. public static
I have seen this question before and found this example in http://www.zeitoun.net/articles/comet_and_php/start which is
Consider this example (typical in OOP books): I have an Animal class, where each
I have tried this example http://www.bennadel.com/blog/1056-ColdFusion-CFPOP-My-First-Look.htm , but it retrieve emails from POP server.
I have looked at this example using php and GD to piecewise-render a spiral
I have a PHP array which looks like this example: $array[0][0] = 'apples'; $array[0][1]
I have a column of type Bit (called BBoolVal in this example). I have
I've simplified this example as much as I can. I have a remote function:

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.