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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:01:54+00:00 2026-05-27T04:01:54+00:00

I am adding an object to a list and then afterwards setting the object

  • 0

I am adding an object to a list and then afterwards setting the object variable to null. To add the another object to the list do i need to create a new object. The code I am using is below:

UpdateData = new MismatchData();
   UpdateData.CINID = currentInLoopCIN_ID;
   UpdateData.ColumnMapID = <some integer>;
   UpdateData.WMSValue = <some integer>;
lsMismatchData.Add(UpdateData);
UpdateData = null;

Do I need to have the first line?

UpdateData = new MismatchData(); //Do I need to have this line of code?
  • 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-27T04:01:55+00:00Added an answer on May 27, 2026 at 4:01 am

    Since you’re setting UpdateDate to null, you’d get an error when you’d try to set UpdateData.CINID, the second time around (you’d be accessing a null object).

    Your null assignment is the redundant line of code here. Since you’re always assigning a new UpdateData to your variable, you don’t need to reset it in between.

    With or without the null assignment, you’ll still need to create a new instance every time, though, otherwise you’d just be updating the old instance.

    If you want to cut down on lines of code, you could do something like this:

    lsMismatchData.Add(new UpdateData {
        CINID = currentInLoopCIN_ID,
        ColumnMapID = <some new integer>,
        WMSValue = <some new integer>
    });
    

    Or, since it looks like you’re in a loop, you might be able to do something like this, to make your code even terser:

    var lsMismatchData = yourLoopSource.Select(x => new UpdateData {
        CINID = x.CIN_ID, // apply your own logic to getting the proper values here.
        ColumnMapID = x.XYZ,
        WMSValue = x.ABC
    }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code I'm currently working on requires adding an NSNumber object to an array.
Outside of a for I declare a variable using var list; . I use
Here's my code: [Serializable()] public class Project { private List<string> _Kinds = new List<string>();
I have a button which I am using to add value from list 1
I am currently using the following code to access the property of an object
I need to deserialize xml file to List or Array then enlarge this List
How does one go about programatically building a TemplateColumn object and adding it to
I am adding several entities to an object context. try { forach (var document
I am adding checkboxes dynamically to silverlight stackpanel object as follows: foreach (String userName
I am dynamically adding an image to a canvas object which was working for

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.