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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:33:44+00:00 2026-05-20T07:33:44+00:00

For example, doing something like this: foreach (DataRow row in data.Rows) { Person newPerson

  • 0

For example, doing something like this:

foreach (DataRow row in data.Rows)
{
    Person newPerson = new Person()
    {
        Id = row.Field<int>("Id"),
        Name = row.Field<string>("Name"),
        LastName = row.Field<string>("LastName"),
        DateOfBirth = row.Field<DateTime>("DateOfBirth")
    };

    people.Add(newPerson);
}

Setting a breakpoint to an individual assignation is not possible, the breakpoint is set to the entire block.

If I want to see specifically where my code is breaking, I have to use:

 foreach (DataRow row in data.Rows)
 {
     Person newPerson = new Person();
     newPerson.Id = row.Field<int>("Id");
     newPerson.Name = row.Field<string>("Name");
     newPerson.LastName = row.Field<string>("LastName");
     newPerson.DateOfBirth = row.Field<DateTime>("DateOfBirth");

     people.Add(newPerson);
 }

Or maybe I’m missing something. Can you properly debug when using an object initializer?

  • 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-20T07:33:45+00:00Added an answer on May 20, 2026 at 7:33 am

    Object initializers are just syntactic sugar and get translated when they’re compiled. Your original object initializer becomes something like this:

    var temp = new Person();
    temp.Id = row.Field<int>("Id");
    temp.Name = row.Field<string>("Name");
    temp.LastName = row.Field<string>("LastName");
    temp.DateOfBirth = row.Field<DateTime>("DateOfBirth");
    var person = temp;
    

    Since the whole block is translated like that you can’t break inside one step. If you absolutely need to break on one particular step, you have a few options.

    1. Break it up. Don’t use object initializers while debugging, and you can put them back afterwords.

    2. Temp variables. Instead of assigning Id = row.Field<int>("Id") directly, assign row.Field<int>("Id") to a temp variable first (or whichever one you want to debug) and then assign the temp variable to the object initializer property.

    3. Method call. You can wrap some of the code in a custom method call solely to allow you to add a breakpoint within your custom method. You could even generalize it like this:

        Id = BreakThenDoSomething(() => row.Field<int>("Id"));
    
        public static T BreakThenDoSomething<T>(Func<T> f)
        {
            Debugger.Break();
            return f();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm using this example implementation found at http://tangentsoft.net/wskfaq/examples/basics/select-server.html This is doing most of what
I am trying to parse a string something like this: Input 20:00 - output
What tools allows me keep track of tags when doing web development? For example,
On mac os console, when doing paste of large quantities of text (for example
What are the things that Medium Trust stops you from doing? For example, I've
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
I have numerous index.php scripts using SEO-friendly arg format like example.com/path/to/index.php/opt/arg and would like
I'm doing a PHP site which displays code examples in various languages (C#, PHP,
Unlike many of the ASP.NET documentation and examples, I'm doing a gridview list on
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe

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.