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

  • Home
  • SEARCH
  • 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 541417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:20:28+00:00 2026-05-13T10:20:28+00:00

The code below compiles, but I don’t understand the behavior of keeping the 1

  • 0

The code below compiles, but I don’t understand the behavior of keeping the 1 element array instead of assigning the two element array. Is there a name for this behavior so that I could search for more information about it? I realize that this code isn’t sensible because the 2 byte array could be assigned in the call to the constructor in GetData.

using System;

public class Item
{
    public Item(string name, byte[] data)
    {
        Name = name;
        Data = data;
    }
    public string Name { get; set; }
    public byte[] Data { get; set; }
}

public class Test
{
    Item member;

    public Test()
    {
        member = new Item("name0", new byte[1]);
    }
    public static void Main()
    {
        Test test = new Test();

        test.member.Data = test.GetData();

        Console.WriteLine("name={0} array={1}", test.member.Name, test.member.Data.Length);
    }

    public byte[] GetData()
    {
        member = new Item("name1", new byte[1]);

        return new byte[2];  
    }
}
  • 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-13T10:20:28+00:00Added an answer on May 13, 2026 at 10:20 am

    Here’s what’s happening:

    1. In new Test(), a new Item (let’s call it object a) is created in the constructor
    2. test.member is evaluated. This will return object a.
    3. test.GetMember() is called, in which:
      1. member is re-assigned a new Item object (we’ll call it object b)
      2. A byte array of length 2 is returned
    4. The Data property of the object retrieved at step #2 (object a) is assigned the two-byte array.
    5. Now, when referencing test.member.Data, test.member has a reference to object b (due to step 3.1)

    This can appear confusing. As far as naming this behavior, it’s all just the evaluation order of statements. The programming technique to avoid this is to not cause side effects in your “Get” methods; get methods should only return values, not change the data of the object.

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

Sidebar

Ask A Question

Stats

  • Questions 345k
  • Answers 345k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In general, people use what is called software configuration management… May 14, 2026 at 5:56 am
  • Editorial Team
    Editorial Team added an answer here's a awk one liner to do that $ cat… May 14, 2026 at 5:56 am
  • Editorial Team
    Editorial Team added an answer You shouldn't be calling onCreateDialog() yourself. Android does that for… May 14, 2026 at 5:56 am

Related Questions

I have the code below : public class Anything { public int Data {
I was wondering if there is any sample code out there for objective-C for
I have a metafunction: struct METAFUNCION { template<class T> struct apply { typedef T
I'm developing a simple Wedding List application, where guests can reserve the present they
So I have a couple of functions that work with a string type I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.