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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:46:16+00:00 2026-06-02T08:46:16+00:00

I just need some help with linkedlists in C#, linked-list in C++ is kinda

  • 0

I just need some help with linkedlists in C#, linked-list in C++ is kinda easy with pointers but im facing some problems in C#
I read the examples provided on http://msdn.microsoft.com but I couldn’t figure out how to link two different linked lists

the efficitent way seems to be having LinkedListNode into a linked list , so lets say I have two linked lists

LinkedList L1 = new LinkedList();
LinkedList L2 = new LinkedList();
and then lets say I have the following nodes

        LinkedListNode<String> Ln1 = new LinkedListNode<String>("Orange");
        LinkedListNode<String> Ln2 = new LinkedListNode<String>("Banana");
        LinkedListNode<String> Ln3 = new LinkedListNode<String>("Apple");
        LinkedListNode<String> Ln4 = new LinkedListNode<String>("Strawberry");

I simply added them to the lists I have :

        L1.AddLast(Ln1);
        L1.AddLast(Ln2);
        L2.AddLast(Ln3);
        L2.AddLast(Ln4);

Ok now lets say I want to link the last element of L1 to the first one in L2 , is that possible ?
I tried this first :

L1.Last.Next = L2.First;
I totally failed with an error : Property or indexer ‘System.Collections.Generic.LinkedListNode&amp;lt;string>.Next’ cannot be assigned to — it is read only

alright I tried this then :

Ln2.Next = Ln3;
I failed again

my last attempt was

        LinkedListNode<String> node1=L1.Last;
        LinkedListNode<String> node2 = L2.First;
        node1.Next = node2;

with an error :Property or indexer ‘System.Collections.Generic.LinkedListNode&amp;lt;string>.Next’ cannot be assigned to — it is read only

so any help please ? how to link them ?

an addition questions :
is there away to reach an element in a linked list by its index for example ?

I came out with this simple algorithm and it works :

         int i = 0;
        foreach (var item in L2)
        {
            Console.WriteLine(item);
            i++;
        }

is there an automatic way ?

thank you for your help

  • 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-02T08:46:18+00:00Added an answer on June 2, 2026 at 8:46 am

    LinkedListNode has property List. This property points to list, which node belongs to. This property is set when you adding node to some list. So, at one time node could belong only to one list. That means you should remove node from one list, before adding it to another:

    var node = L2.First;
    L2.RemoveFirst();
    L1.AddLast(node);
    

    If you want to add all nodes from L2, you can use:

    while (L2.Count > 0)
    {
        var node = L2.First;
        L2.RemoveFirst();
        L1.AddLast(node);
    }
    

    Keep in mind, it will remove all nodes from L2.

    Another option – create new nodes with same values:

    foreach (string value in L2)
        L1.AddLast(value);
    

    UPDATE: If you want to reach an element in a linked list by its index, you can just skip first N items and take next one:

    L1.Skip(index).First()
    

    As with any collection, you should verify, that list has at least N-1 nodes.

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

Sidebar

Related Questions

this might be really simple, but just need some help in getting the syntax
I need some help with jQuery script again :-) Just trying to play with
I'm just starting out with the whole ajax thing and I need some help.
I got some code off the Internet and now I just need help to
I need some help in understanding what the Eval bit does (Just started learning
I just need some quick help on syntax. I'm doing a WPF project and
Just need some help to refine this query if possible. SELECT * FROM E_Associates
Just need some help taking this hierarchical array... Array ( [root] => Array ([attr]
Just need some help with this. I have written a WCF service which passes
I really need some help with forming a MySQL query that I just cannot

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.