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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:12:09+00:00 2026-05-27T16:12:09+00:00

so out of the following 3 examples that do the same thing i really

  • 0

so out of the following 3 examples that do the same thing i really lean towards the first but is it really overkill and an abuse of linq to do things that way where you can create it all as an expression

  var Rand = new Random();
        Hosts = "abcdef".Select(x =>
                    {
                        return new HostMachineToUpdate(x + "_Host",
                            Enumerable.Range(1, Rand.Next(3, 8))
                            .Select(y => new VirtualMachineToUpdate(x + y.ToString() + "_VM")).
                            ToList()
                            );
                    }
                )
                .ToList();

        //traditional
        Hosts = new List<HostMachineToUpdate>();
        for (int x = (int)'a'; x < (int)'e'; x++)
        {
            var Guests = new List<VirtualMachineToUpdate>();
            for (int y = 1; y < (new Random().Next(3, 8));y++ )
            {
                Guests.Add(new VirtualMachineToUpdate((char)x + y.ToString() + "_VM"));
            }
            Hosts.Add(new HostMachineToUpdate((char) x + "Host",Guests));
        }

        //very traditional.
        Hosts = new List<HostMachineToUpdate>();
        int lower = (int)'a';
        int upper = (int)'e';
        for (int x = lower; x < upper; x++)
        {
            List<VirtualMachineToUpdate> Guests = new List<VirtualMachineToUpdate>();
            int randomItemNum = new Random().Next(3, 8);
            for (int y = 1; y < randomItemNum; y++)
            {
                string vmname = (char)x + y.ToString() + "_VM";
                VirtualMachineToUpdate vm = new VirtualMachineToUpdate(vmname);
                Guests.Add(vm);
            }
            string hostname = (char)x + "Host";
            HostMachineToUpdate host = new HostMachineToUpdate(hostname, Guests);                
            Hosts.Add(host);
        }
  • 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-27T16:12:10+00:00Added an answer on May 27, 2026 at 4:12 pm

    I personally don’t like the amount of casting used in your traditional solution.

    Is all the casting actually needed ?

    Wouldn’t this (untested) code also do what is required?

        // traditional.
        Hosts = new List<HostMachineToUpdate>();
        foreach (char x in "abcd")
        {
            List<VirtualMachineToUpdate> Guests = new List<VirtualMachineToUpdate>();
            int randomItemNum = new Random().Next(3, 8);
            for (int y = 1; y < randomItemNum; y++)
            {
                Guests.Add(new VirtualMachineToUpdate(x + y.ToString() + "_VM"));
            }
            Hosts.Add(new HostMachineToUpdate(x + "Host", Guests));
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an algorithm for figuring out the following things? If the result of
This really should be easy, but I just can't work it out myself, the
Using the following example, I need to filter out the line containing 'ABC' only,
I'm trying to figure out how XSLT process namespace prefixes and have following example:
check out the following test: http://binks.knobbits.org/webgl/texture3.html It's a simple test of cube textures. It
Please check out the following func and its output void main() { Distance d1;
I was trying out the following code which actually saves the pdf file to
Please check out my following code... public enum LogType { Debug, Info, Warn, Error,
I want to find out the following: given a date ( datetime object), what
i am trying to work out the following problem in Java (although it could

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.