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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:05:30+00:00 2026-05-28T05:05:30+00:00

I know this is a little bit hypothetical, because I am not looping this,

  • 0

I know this is a little bit hypothetical, because I am not looping this, it only occurs once or twice in a program run, and so it will only be a completely unnoticable amount of time, but I want to know if one of these is better than the other, or if it doesn’t matter at all, because the optimiser will optimise away the worse code.

I have this class:

class FOO_Data
{
    private string description, url;
    private bool editable;

    public FOO_Data(string description, string url, bool editable)
    {
        this.description = description;
        this.url = url;
        this.editable = editable;
    }

    public string Description { get { return description; } set { description = value; } }
    public string URL { get { return url; } set { url = value; } }
    public bool Editable { get { return editable; } set { editable = value; } }
} 

At some other point in my code, I need to edit an instance of this class in an array of this class.

Which one is better? This one:

array[index] = new FOO_Data(data.Description, data.URL, System.Convert.ToBoolean(data.Editable));

or this one:

array[index].Description = data.Description;
array[index].Editable = Convert.ToBoolean(data.Editable);
array[index].URL = data.URL;

I would tend towards the first, but I am not very sure. I would appreciate any insight you could offer.

Thanks a lot!

  • 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-28T05:05:31+00:00Added an answer on May 28, 2026 at 5:05 am

    If array[index] is null, the second bit of code, trying to access members will throw a NullReferenceException.

    This can’t happen with the first bit of code, where you are assigning a newly constructed FOO_Data object.

    In terms of performance, you are unlikely to see any difference if the array is indeed fully populated as object creation is a very light process.

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

Sidebar

Related Questions

I know this has a stupid solution but, sorry, I'm little bit confused. I
This one is a huge issue: first off, while I know a little bit
This little bit of code will help me describe my problem: public class Car
I know this may sound silly little bit, but there is no other way
I know this question might sound a little bit crazy, but I tough that
I know this sounds a little bit specific but I was just wondering where
I know I can improvise this little bit (eliminate explicit throw) by using Preconditions
I know this question might sound a little cheesy but this is the first
I have little question about how web browser retrieve webpage? I know this User
My apologies if this is a little broad, but I'm struggling to know where

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.