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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:52:44+00:00 2026-06-04T15:52:44+00:00

I have a City class and inside that a Detail class: public class City

  • 0

I have a City class and inside that a Detail class:

public class City {

        public string PartitionKey { get; set; }
        public string RowKey { get; set; }
        public string Notes { get; set; }

        public class Detail
        {
            public Detail()
            {
                ImageFile = String.Empty;
                Explanation = new HtmlText();
            }
            public string ImageFile { get; set; }
            public HtmlText Explanation { get; set; }
        }

}

In my code I have some lines that check how many details there are and if there are less than ten then I add new City.Details. I am using the code below to do this but it’s located in a few different methods and does not look clean. Is there some way that I could simplify this and also add the logic of checking, counting and adding into my base City class?

foreach (int index in Enumerable.Range(0, 10 - vm.Details.Count()))
            {
                vm.Details.Add(new City.Detail());
            }
  • 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-06-04T15:52:46+00:00Added an answer on June 4, 2026 at 3:52 pm

    As the others said, use something like the following

     while(vm.Details.Count() < 10)
          vm.Details.Add(new City.Detail());
    

    or even a regular for construct

     for(int x = vm.Details.Count(); x < 10; x++)
          vm.Details.Add(new City.Detail());
    

    Otherwise when other people read your code (or you look at it 3 months from now) the reaction is going to be “huh?” instead of just automatically recognizing what’s happening.

    Here are three ways to address the problem:

    1) Just add ten Details to the City object when you create it, use those and then create more if/when necessary

    2) Why do you need 10 Details if there aren’t really 10 Details? As much as possible it’s best to have your objects truly represent what they are… representing. So perhaps you are trying to fix what is just a symptom of a deeper problem. But if that’s not the case, then…

    3) As the others have mentioned just move this logic into your base class.

    Edit: I should have also made clear on #3 that you need a way to make this process automatic so you don’t have to explicitly call the procedure that pads it with extra Details. I don’t have enough info from your code to know how exactly to tell you to do this but if you want to provide more info as to why it’s important to have 10 Details then I’m sure I could help further.

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

Sidebar

Related Questions

I have a TreeMap that maps String keys to a custom City class. Here
I have this small class called City that simply holds some information about a
So I have a few Django models that look like this: class City(models.Model): name
I have a Java model similar to: public class Country { @Id private String
I have a custom dialog inside public class NewPartnerDialog extends Dialog implements OnClickListener And
Say I have these two models: public class City extends Model { @ManyToOne private
I have a user class that contains name, email, city, state, zip. This is
I have the following models: class City(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name =
I have a city table that has two columns from_city to_city now lets assume
I have a conceptual Python design dilemma. Say I have a City class, which

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.