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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:45:26+00:00 2026-05-25T14:45:26+00:00

.NET seems to have a lot of data structure and collection types. Does it

  • 0

.NET seems to have a lot of data structure and collection types. Does it have a first-in-first-out collection with a maximum size and no duplication, or something similar to that?

An example usage would be like for storing 5 most recently opened files. If a 6th object is added, dequeue the least recent object to keep the size to 5

  • 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-25T14:45:26+00:00Added an answer on May 25, 2026 at 2:45 pm

    You’ll have to create a QueueSet that implements ICollection<T>. It can be a wrapper class that contains a collection as a backing store. It can be implemented as follows:

    class QueueSet<T> : ICollection<T> 
    {
        List<T> queue=new List<T>();
        int maximumSize;
    
        public QueueSet(int maximumSize){
            if(maximumSize<0)
                throw new ArgumentOutOfRangeException("maximumSize");
            this.maximumSize=maximumSize;
        }
    
        public T Dequeue(){
            if(queue.Count>0){
                T value=queue[0];
                queue.RemoveAt(0);
                return value;
            }
            return default(T);
        }
    
        public T Peek(){
            if(queue.Count>0){
                return queue[0];
            }
            return default(T);
        }
    
        public void Enqueue(T item){
            if(queue.Contains(item)){
                queue.Remove(item);
            }
            queue.Add(item);
            while(queue.Count>maximumSize){
                Dequeue();
            }
        }
    
        public int Count {
            get {
                return queue.Count;
            }
        }
    
        public bool IsReadOnly {
            get {
                return false;
            }
        }
    
        public void Add(T item)
        {
            Enqueue(item);
        }
    
        public void Clear()
        {
            queue.Clear();
        }
    
        public bool Contains(T item)
        {
            return queue.Contains(item);
        }
    
        public void CopyTo(T[] array, int arrayIndex)
        {
            foreach(T value in queue){
                if(arrayIndex>=array.Length)break;
                if(arrayIndex>=0){
                    array[arrayIndex]=value;
                }
                arrayIndex++;
            }
        }
    
        public bool Remove(T item)
        {
            if(Object.Equals(item,Peek())){
               Dequeue();
               return true;
            } else {
                return false;
            }
        }
    
        public IEnumerator<T> GetEnumerator()
        {
            return queue.GetEnumerator();
        }
    
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return queue.GetEnumerator();
        }
    }
    

    I release this code into the public domain.

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

Sidebar

Related Questions

The .NET Setup project seems to have a lot of options, but I don't
Does anyone have the installer for IronXSLT? xmllab.net seems to have gone down and
It seems the java.net.NetworkInterface implementation of android does not have a byte[] getHardwareAddress() method
Although ASP.NET MVC seems to have all the hype these days, WebForms are still
As Microsoft seems to have started their trickle feed of information regarding .NET 4.0,
The LinearGradientBrush in .net (or even in GDI+ as a whole?) seems to have
We have just setup our hudson server to build .NET projects which seems to
I have a .NET 2.0 server that seems to be running into scaling problems,
It seems like when you have a WinForms .NET application, and a ComboBox (set
I have a .NET DLL that writes to the Trace. But it seems that

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.