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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:29:42+00:00 2026-05-25T19:29:42+00:00

Currently I have a simple class for users, like the follow: public class Users

  • 0

Currently I have a simple class for users, like the follow:

public class Users
{
    public int ID { get; set; }
    public string Name { get; set; }
    public Groups Access { get; set; }
    public IPAddress IP { get; set; }
    public bool IsProtected { get; set; }
    public bool IsInvisible { get; set; }
}

Now I would like to store the user last 3 sent messages and be able to compare if user new last message matchs with any of the previous 3 stores messages and if not remove the oldest message from the list and add the new one.

I was initially thinking of simple using a list of strings and go for something like this:

bool msg_match = user.LastMessages.Any(x => String.Equals(x, msg, StringComparison.OrdinalIgnoreCase));
if (msg_match)
{
    // punish user
    user.LastMessages.Clear();
}
else
{
    // some way to remove oldest message and leave only the 3 newest messages
    user.LastMessages.Add(mensagem);
}

The above method do work but I am a bit clueless on how to pick the oldest message to be removed resulting in the last the newest messages and also a not sure if this method would be ok or if there is a better way to approach this ?

PS: My title sounds rather confusing I think if you have a better idea for the title let me know or change it pls.

  • 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-25T19:29:43+00:00Added an answer on May 25, 2026 at 7:29 pm

    You could store the messages in a LinkedList<string>. This would make it simple to do you check:

    bool msg_match = user.LastMessages.Any(x => String.Equals(x, msg, StringComparison.OrdinalIgnoreCase));
    if (msg_match)
    {
        // punish user
        user.LastMessages.Clear();
    }
    else
    {
        // some way to remove oldest message and leave only the 3 newest messages
        user.LastMessages.AddFirst(mensagem);
        if (user.LastMessages.Count > 3)
            user.LastMessages.RemoveLast();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get more in to TDD. Currently keeping it simple
Basically I have a simple base class: public abstract class BasePoco { public virtual
I have the following simple models: class Event < ActiveRecord::Base has_many :participations has_many :users,
I am currently using Django Users model. Very simple. However, I'd like to add
I currently have a custom session handler class which simply builds on php's session
I have a simple class that contains some general information about the current web
I currently have a simple form that when you click the save button will
There is probably is simple fix for this but I currently have code similar
I have a simple ticket logging application build on LAMP. I am currently playing
I am currently learning F# and have tried (an extremely) simple example of FizzBuzz.

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.