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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:23:44+00:00 2026-06-10T05:23:44+00:00

I’m trying to write a custom LinkedList class in C# using monoDevelop on Linux,

  • 0

I’m trying to write a custom LinkedList class in C# using monoDevelop on Linux, just for the sake of testing and learning. The following code never compiles, and I have no idea why!! It doesn’t even tell me what’s wrong. All what it says is: Error: The compiler appears to have crashed. Check the build output pad for details. When I go to check the output pad, it’s not helpful either:
Unhandled Exception: System.ArgumentException: The specified field must be declared on a generic type definition.
Parameter name: field

What can I do?

using System;
using System.Text;
using System.Collections.Generic;

namespace LinkedList
{
    public class myLinkedList<T> : IEnumerable<T>
    {
        //List Node class
        //===============
        private class ListNode<T>
        {
            public T data;
            public ListNode<T> next;

            public ListNode(T d)
            {
                this.data = d;
                this.next = null;
            }

            public ListNode(T d, ListNode<T> n)
            {
                this.data = d;
                this.next = n;
            }
        }

        //priavte fields
        //===============
        private ListNode<T> front;
        private int size;

        //Constructor
        //===========
        public myLinkedList ()
        {
            front = null;
            size = 0;
        }


        //public methods
        //===============
        public bool isEmpty()
        {
            return (size == 0);
        }

        public bool addFront(T element)
        {
            front = new ListNode<T>(element, front);
            size++;
            return true;
        }

        public bool addBack(T element)
        {
            ListNode<T> current = front;
            while (current.next != null)
            {
                current = current.next;
            }

            current.next = new ListNode<T>(element);
            size++;
            return true;
        }

        public override string ToString()
        {
            ListNode<T> current = front;
            if(current == null)
            {
                return "**** Empty ****";
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                while (current.next != null)
                {
                    sb.Append(current.data + ", ");
                    current = current.next;
                }
                sb.Append(current.data);

                return sb.ToString();
            }
        }

        // These make myLinkedList<T> implement IEnumerable<T> allowing
        // a LinkedList to be used in a foreach statement.
        public IEnumerator<T> GetEnumerator()
        {
            return new myLinkedListIterator<T>(front);
        }


        private class myLinkedListIterator<T> : IEnumerator<T>
        {
            private ListNode<T> current;
            public virtual T Current
            {
                get
                {
                    return current.data;
                }
            }
            private ListNode<T> front;

            public myLinkedListIterator(ListNode<T> f)
            {
                front = f;
                current = front;
            }

            public bool MoveNext()
            {
                if(current.next != null)
                {
                    current = current.next;
                    return true;
                }
                else
                {
                    return false;
                }
            }

            public void Reset()
            {
                current = front;
            }

            public void Dispose()
            {
                throw new Exception("Unsupported Operation");
            }
        }
    }
}
  • 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-10T05:23:45+00:00Added an answer on June 10, 2026 at 5:23 am

    You need to add the non-generic APIs; so add to the iterator:

    object System.Collections.IEnumerator.Current { get { return Current;  } }
    

    and to the enumerable:

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
    

    HOWEVER! If you are implementing this by hand, you are missing a trick. An “iterator block” would be much easier.

    The following is a complete implementation; you don’t need to write an enumerator class at all (you can remove myLinkedListIterator<T> completely):

    public IEnumerator<T> GetEnumerator()
    {
        var node = front;
        while(node != null)
        {
            yield return node.data;
            node = node.next;
        }
    }
    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of 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.