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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:31:12+00:00 2026-05-20T10:31:12+00:00

My console app will loop through each User to get their Websites, so that

  • 0

My console app will loop through each User to get their Websites, so that it can take new screenshots of them. However, to prevent taking screenshot of the same website twice I have to check whether there already has been taken screenshot of the website, while looping through another users websites.

My current solution is:

Database:

User
|--> ID: 1
|--> FirstName: Joe

|--> ID: 2
|--> FirstName: Stranger

Websites
|--> ID: 1
|--> UserID: 1
|--> URL: http://site.com

|--> ID: 2
|--> UserID: 2
|--> URL: http://site.com

Console app:

static void RenewWebsiteThumbNails()
{
    Console.WriteLine("Starting renewal process...");

    using (_repository)
    {
        var websitesUpdated = new List<string>();

        foreach (var user in _repository.GetAll())
        {
            foreach (var website in user.Websites.Where(website => !websitesUpdated.Contains(website.URL)))
            {
                _repository.TakeScreenDumpAndSave(website.URL);
                websitesUpdated.Add(website.URL);

                Console.WriteLine(new string('-', 50));
                Console.WriteLine("{0} has successfully been renewed", website.URL);
            }
        }
    }
}

However, it seems wrong to declare a List for such a scenario, just to check whether a specific URL already has been added… any suggestions for an alternative way?

  • 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-20T10:31:13+00:00Added an answer on May 20, 2026 at 10:31 am

    You can use

     var websitesUpdated = new HashSet<string>();
    

    Cost of the operation O(1) instead of O(n) in list case.

    EDIT:
    By the way I would take all urls from each user and put them all in one HashSet so there won’t be any duplicates and then just iterate on HashSet as it is a simple list.

    Some think like this.

    var websites = new HashSet<string>();
    foreach (var url in   _repository.GetAll().SelectMany(user=>user.Websites))
      websites.Add(url);
    

    After this,

    foreach (var website in websites)
    {
    Console.WriteLine(new string('-', 50)); 
    Console.WriteLine("{0} has successfully been renewed",website.URL);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .Net console App which using a scheduled event will start, call
I have a console app that needs to display the state of items, but
I have a C# console app App1 that reads a row of data from
I have one console app that is doing some lengthy syncing to an ftp
I would prefer that a console app would default to multithreaded debug. warning level
I've written a .NET console app that wraps CuteFTP's Transfer Engine - a COM
I am trying to write a console app that simply lists the number of
I am creating a small console app that needs a progress bar. Something like...
While testing a console app, I set the properties of the console window to
I'm writing some excel-like C++ console app for homework. My app should be able

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.