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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:54:07+00:00 2026-05-16T04:54:07+00:00

I have a subroutine that changes its operation slightly to include either one list

  • 0

I have a subroutine that changes its operation slightly to include either one list or the other then perform the same operation. Since it is just counting the number of items in the list, I figure there is probably an easy way to get the item count regardless of the list type.

Thanks in advance!

EDIT:

private List<Message> currentMessages;
private List<Lead> currentLeads; 
...
private void nextLeadBtn_Click(object sender, EventArgs e)
    {
        object temp;
        if (includeAllCheck.Checked)
        {

            temp = currentMessages;
            if (SelectedLead == (currentMessages.Count - 1))
                SelectedLead = 0;
            else
                SelectedLead += 1;
        }
        else
        {
            temp = currentLeads;
            if (SelectedLead == (currentLeads.Count - 1))
                SelectedLead = 0;
            else
                SelectedLead += 1;  
        }
        // This is what I want to replace the above with
        //if (SelectedLead == ((List)temp).Count - 1) //obviously this does not work
        //    SelectedLead = 0;
        //else
        //    SelectedLead += 1;




        LoadPreviews(includeAllCheck.Checked);
    }
  • 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-16T04:54:08+00:00Added an answer on May 16, 2026 at 4:54 am

    You can always use ICollection.Count, if you don’t want to deal with generics. List<T> implements ICollection, so you can always access that.

    EDIT: So now that you’ve posted your code, you can just change the line:

    if (SelectedLead == ((List)temp).Count - 1)  // won't compile, of course
    

    to

    if (SelectedLead == ((ICollection)temp).Count - 1)  // happy as a clam
    

    In fact, an even better option would be to change the declaration of object temp to ICollection temp to better convey the type information, and avoid all of this casting nonsense altogether.

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

Sidebar

Ask A Question

Stats

  • Questions 522k
  • Answers 522k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to supply the filename to the find command:… May 16, 2026 at 9:18 pm
  • Editorial Team
    Editorial Team added an answer You can't open the same file as an istream and… May 16, 2026 at 9:18 pm
  • Editorial Team
    Editorial Team added an answer You can insert a space after the opening bracket of… May 16, 2026 at 9:18 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I've inherited a 10K-line program written in 8051 assembly language that requires some changes.
I am writing a comparefiles subroutine in Perl that reads a line of text
So I have a file that in short has this problem... #!/usr/bin/perl -w package
I have a VBA application that creates an instance of a COM object and
I have a VB6 program which I've been maintaining for ten years. There is
I have some code which is effectively this: class dummie_type { public: int a;
I have some Perl modules which exports various functions. (We haven't used @EXPORT in
I have a piece of Perl code somewhat like the following (strongly simplified): There
First off, I'm not really sure how much information is necessary to include because
I have a pointer to a COLORREF buffer, something like: COLORREF* buf = new

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.