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

The Archive Base Latest Questions

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

I want to say that my code works correctly but i don’t know why

  • 0

I want to say that my code works correctly but i don’t know why it is working like that. So to make it clear, here is my code:

List<NewsFlash> newsfl = tsm.getNewsFlashes();

foreach (NewsFlash item in newsfl)
{
    item.smartform.dtDate = item.smartform.dtDate.ToShortDateString();
}

//Get all the newsFlash items and bind to the repeater
rptNewsFlash.DataSource = newsfl;
rptNewsFlash.DataBind();

Like you can see, I am looping the list newsfl and I am editing item.smartform.dtDate. What is weird for me is, when I edit item.smartform.dtDate, then the property dtDate in the list newsfl is also changed. This is what I want, but it is kind of weird I think, because item within the foreach loop has nothing to do with the list newsfl?

Hope you understand my question.

Thanks

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

    Each item in the foreach is just a reference to the item at a specific index within newsfl – so when your loop is done, you’ve updated all the item‘s in the list, and those items hang onto those changes. This makes sense because each item is not a copy of the original, it is the original.

    So, imagine item and newsfl[n] as two doors to the same room, you end up in the same place – and it doesn’t matter which door I arrive through, if I start moving furniture around, it is also moved for anyone who comes in through either door.

    On another note, if this didn’t happen, then what would you expect to happen? Since you make changes to item, surely you want to keep them?

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

Sidebar

Related Questions

the code below is working, but I want to make sure it's correct .
First thing i want to say that it's not an easy question to explain,
First off I want to say that I am not using threads or multiple
First of all i want to say that i have searched each and every
First of all i want to say that I'm still a beginner in ASP.NET
First, I just want to say that the stackoverflow community is empowering to say
In my regex, I want to say that within the sample text, any characters
So say that I want to find the word Hello, world! on a webpage.
Let's say that I want to use C-style arrays of NSObjects instead of using
Lets say that I have an executable and when it is started I want

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.