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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:42:28+00:00 2026-05-15T21:42:28+00:00

How do I check for null in a array list and remove them? It

  • 0

How do I check for null in a array list and remove them? It keeps giving me a error of “ArgumentOutOfRange was handled” or if I change the SMTPException to just Exception it says “Index out of range”. Looking at the debugger and taking a look specifically at mails.Count it gives me Count = 4. I originally gave it 3 emails to check. The last Array is a “”. I believe this is causing the problem.

private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (textBox1.Text == "")
            {
                textBox3.Text += "[-] Listbox is Empty!!!!\r\n";
                return;
            }
            // textBox1.Text.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); 
            // Grabs Emails supplied in textbox1 amd then seperates array using '\n'
            ArrayList mails = new ArrayList(textBox1.Text.Split('\n')); 

            // Note: For thought 
            // IEnumerable<string> myResults = mails.Split('\n').Where<string>(s => !string.IsNullOrEmpty(s));
            for (int i = 0; i < mails.Count; i++)
            {
                // Seperates user & pass to be passed for authentification.
                ArrayList mailInfo = new ArrayList(mails[i].ToString().Split(':'));
                textBox3.Text += "[+] Checking email format for" + "\r\n" + "[/] " +  mails[i] + "\r\n";
                // Attach domain name if not attached.
                if (!mailInfo[0].ToString().EndsWith("@gmail.com")) mailInfo[0] = mailInfo[0] + "@gmail.com"; 

                // Debug:  Check point
                // 
                // Error message:
                // Index was out of range. Must be non-negative and less than the size of the collection. Parameter name index. 
                // mails.Count = 4 when feeding only 3 emails.
                //
                // Function:  Check mail & Password
                // error: index out of range
                // MessageBox.Show(mailInfo[0].ToString() + "\n\n" + mailInfo[1].ToString());
                if (mails[i] == "") throw new ArgumentOutOfRangeException("No Mail", "No more mail to check.");
                if (checkAccount(mailInfo[0].ToString(), mailInfo[1].ToString()))
                {
                    textBox3.Text += "[+] Connection Successful! Checking mail.: mailInfo[0].ToString()\r\n";
                }
            }
        }

What am I doing wrong??? Is the null my problem and if so how do I remove it or am I missing something?

  • 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-15T21:42:29+00:00Added an answer on May 15, 2026 at 9:42 pm

    Try populating the array like this:

    ArrayList mails = new ArrayList(textBox1.Text.Trim().Split('\n'));
    

    That should remove any trailing white space and remove that last item from getting into the array.

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

Sidebar

Related Questions

Basically I just want to check if one time period overlaps with another. Null
The if(variable) clause in the following constructs checks if list/array is not null/undefined, to
Our application is developed using Spring framework. Is it good practice to check null
USING MS ACCESS 2003 How to check is null value in the access database?
It seems like my code works to check for null if I do if
I have this: If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then stTransactionPaymentID = editTransactionRow.pay_id 'Check for null
If I want to check for the null string I would do [ -z
Is it best to check for a null User when trying to access UserID
How to check a value IS NULL [or] = @param (where @param is null)
JNI: How can i check if jobject is a null object in native c

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.