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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:34:09+00:00 2026-05-15T12:34:09+00:00

Before posting my question, I would like to tell you that I have no

  • 0

Before posting my question, I would like to tell you that I have no prior experience in .Net technologies and have recently started to learn C# (and WPF). My company is looking to move onto .Net technologies and I am the only one in my team learning it, so have noone apart from you guys to discuss or ask something. So if my questions are too stupid or basic at best, please bear with me.

I was trying to create a generic linked list class to allow creation of linked lists of different types. I wrote the following code and would like to have your advise on whether I have written this code properly or not. Any suggestions to improve the code in any way is most welcome.

Main program

class Program
{
    static void Main(string[] args)
    {
        GenLinkedList<string> list = new GenLinkedList<string>("abc");
        list.AddtoList("def");
        int i = 0;
        string[] arr = new string[10];
        list.LinkedList.CopyTo(arr,0);
        for (i = 0; i < list.LinkedList.Count; i++)
        {
            Console.WriteLine(arr[i]);
        }

        GenLinkedList<int> listInt = new GenLinkedList<int>(1);
        listInt.AddtoList(2);
        i = 0;
        int[] arrInt = new int[10];
        listInt.LinkedList.CopyTo(arrInt, 0);
        for (i = 0; i < listInt.LinkedList.Count; i++)
        {
            Console.WriteLine(arrInt[i]);
        }

    }
}

Class GenLinkedList

public class GenLinkedList<T>
{
    private LinkedList<T> _linkedlist;
    public GenLinkedList(T a)
    {
        _linkedlist = new LinkedList<T>();
        _linkedlist.AddLast(a);
    }

    public LinkedList<T> LinkedList
    {
        get
        {
            return _linkedlist;
        }
    }

    public void AddtoList(T a)
    {
        LinkedList.AddLast(a);
    }
}
  • 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-15T12:34:09+00:00Added an answer on May 15, 2026 at 12:34 pm

    1

    A generic linked list implementation already exists in the .NET framework: LinkedList<T>. But you already know that; your code wraps it.

    2

    OK, so you know that. Why would you wrap it, then? The only functionality you appear to have implemented is AddtoList, which doesn’t do anything the LinkedList<T> doesn’t already do itself (after all, this is only a thin wrapper around LinkedList<T>.AddLast). What this means is that your GenLinkedList<T> class really doesn’t offer the functionality of a linked list; it’s basically an add-only collection (which could just as easily have been implemented with a List<T>, or a Stack<T>, or a Queue<T> — anything, really).

    3

    Assuming you do have a good reason to wrap a LinkedList<T> (e.g., you’re planning to add more functionality down the line that would actually leverage the behavior of a LinkedList<T> and/or — here’s a key ingredient — you want to restrict the way calling code is able to interact with the list (e.g., no removals)), you really shouldn’t expose your LinkedList<T> member at all. The purpose of a wrapper is just that: to wrap. You take an existing class and basically give it a new kind of interface. By exposing the underlying object directly, you cripple your wrapper. Any additional restrictions/validation/logic you have in your wrapper can be bypassed.

    So, for example, if you want to be able to copy your list to an array, instead of doing this:

    list.LinkedList.CopyTo(arr,0);
    

    You would implement a CopyTo method within your GenLinkedList<T> class (which could simply call _linkedlist.CopyTo) and use that.

    But I really think the first question you should be asking yourself is what you want to accomplish by wrapping LinkedList<T> in the first place.

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

Sidebar

Related Questions

Before posting my question to the ActiveState forum, I'd like to try luck here
Like many other people posting questions here, I recently started programming in Python. I'm
NOTE : Right before posting this question it occurred to me there's a better
I searched StackOverflow before posting this question but I wasn't able to find the
Before you all get pissy about me posting this question again, let me explain
before I start I want to point out that I tagged this question as
Before asking the question let me preface with the fact that I am new
Before asking my question, let me explain the context. CONTEXT: I have a web
(Before I start, yes I have asked a similar question before; unfortunately due to
Hey guys. Working on Mac OSX 10.6, My problem is that I would like

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.