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

  • Home
  • SEARCH
  • 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 8370875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:01:07+00:00 2026-06-09T14:01:07+00:00

Assuming I have some objects like this: Class NetworkSwitch { private String _name; String

  • 0

Assuming I have some objects like this:

Class NetworkSwitch
{  
   private String _name; 
   String name { get {return _name;} set {_name=value;}}
   Dictionary<int, VLAN> VLANDict = new Dictionary<int, NetworkSwitch>();

public List<CiscoSwitch> GetAllNeigbors()
         {
           List<CiscoSwitch> templist = new List<CiscoSwitch>();

        foreach (KeyValuePair<int, CiscoVSAN> vlanpair in this.VLANDict)
        {

            templist.AddRange((vlanpair.Value.NeighborsList.Except(templist, new SwitchByNameComparer())).ToList());
        }
        return templist;
}

Class VLAN
{ 
  private Int _VLANNum;
  Int VLANNum {get {return _VLANNum ;} set {_VLANNum =value;}}

  //a neighbor is another switch this switch is connected to in this VLAN
  // the neighbor may not have all same VLANs
  List<NetworkSwitch> Neighbors = new List<NetworkSwitch>();
}

the above is designed that way because two switches that are physically connected may not have all the same VLANs assigned. what I am attempting to do is step through the Neighbors list in each VLAN on a given switch and update the reference to another switch if the name matches one in an input list. Here is what I tried and it won’t compile. I am wondering if LINQ can do it in place somehow, or if there is a better approach.

// intersect is the input list of NetworkSwitch objects
//MyNetworkSwitch is a previously created switch

foreach (NetworkSwitch ns in intersect)
{
  foreach (KeyValuePair<int, VLAN> vlanpair in MyNetworSwitch.VLANDict)
  {
      foreach (CiscoSwitch neighbor in vlanpair.Value.Neighbors)
      {   // this is the line that fails - I can't update neighbor as it is part of the foreach
          if (ns.name == neighbor.name) { neighbor = ns; }
      }
  }
}

Another question – I added the method that gets all the neighbors for a NetworkSwitch object. Assuming I were to get that list, then update it with references to a different instance of the switch with the same name, would that update the reference in the VLAN for the NetworkSwitch object?

  • 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-09T14:01:08+00:00Added an answer on June 9, 2026 at 2:01 pm

    Something like this should work:

            foreach (NetworkSwitch ns in intersect) 
            {   
                foreach (KeyValuePair<int, VLAN> vlanpair in ns.VLANDict)
                {
                    if(vlanpair.Value.Neighbors.RemoveAll(n => n.name == ns.name) > 0)
                        vlanpair.Value.Neighbors.Add(ns);
                } 
            } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have some object like, with LOTS of properties: public class SomeObject {
Needed some help with my logic again. Assuming the Loan class exists, I have
I have seen examples containing things like this: mountSharedResource(/images/logo.gif, new ResourceReference(ImageScope.class, logo.gif).getSharedResourceKey()); mountSharedResource(/resource, Application.class.getName()
Assuming I have a class like public class FooImpl { public void bar(){}; }
I have come across some strange behaviour, and I'm assuming a bug in Firefox,
Assuming I have a numerical string: var foo = 0; Assume I want to
I have my own db class which has some purpose built functions that I
I'd like to know how multiprocessing is done right. Assuming I have a list
I have some trouble reading file in Java. What a file looks like: Answer
In a groovy swing application, I have a class that represents teachers like the

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.