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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:41:33+00:00 2026-05-29T22:41:33+00:00

I am trying to search a list and then extract some objects of it

  • 0

I am trying to search a list and then extract some objects of it put them into another list and write the list to a file.

I think that my code is right but when I execute it I get a NullReference exception. If someone could check my code would I would be really grateful.

Here’s my code for the Search method that I use

public void Search( string day)
{
    foreach (Classes c in studentClasses)
    {
        if (c.Day == day)
        {
            studentClassesByDay.Add(c);
        }
    }
}

And that’s the code which adds the new list to a file

private void btnDay_Click(object sender, EventArgs e)
    {
        SelectDayForm selectDay = new SelectDayForm();
        if (selectDay.ShowDialog() == DialogResult.OK)
        {
            l.Search(selectDay.theDay);
            trg.GenerateSortedListReport(l.studentClassesByDay, AppData.byDay);
            MessageBox.Show("A list of sorted student classes written to file " + AppData.byDay+ ".");
           // txtDay.Text =selectDay.theDay;

        }
    }
  • 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-29T22:41:34+00:00Added an answer on May 29, 2026 at 10:41 pm

    You haven’t shown on which line the exception occurs (which would be handy) but you also haven’t shown where studentClassesByDay has been instantiated.

    That would be the first thing I would check.

    The only possibilities in the code you’ve shown are:

    • l is null;
    • trg is null;
    • l.studentClassesByDay is null; or
    • AppData is null (though that’s probably not so – it looks like a class).

    Simply put some debug statements (or breakpoints in your debugger) before each attempted dereference and check the values.

    Based on your comment that the errant line is:

    studentClassesByDay.Add(c);
    

    it’s almost guaranteed (as suspected) that you havent actually instantiated this variable. I’d look into that.

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

Sidebar

Related Questions

I'm trying to build a search engine that will check a list and then
I am trying to write a simple bash script that will search for files
I was trying to search through a list of pairs that could have the
I'm trying to figure out how to search a list of names that are
I'm trying to write a program that checks a list of names entered by
I am trying to read in a file that has HTML list items with
I'm trying to write a function that does the following: Given a text file,
I am trying to write a custom comparer to sort a list of search
im trying to write a code that should allow me to search a string
I'm trying to search through the p tag content inside the .list and I'm

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.