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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:45:09+00:00 2026-06-08T08:45:09+00:00

C# : I am trying to create collection class with list of some other

  • 0

C# : I am trying to create collection class with list of some other user defined class but it show object not set to be an instance of an object when i trying to add object in main object.
Here is my C# code :

namespace ConsoleApplication2
{

   public class Monthlst
    {
        public List<Monday> Monday { get; set; }
        public List<Tuesday> Tuesday { get; set; }
        public List<Wednesday> Wednesday { get; set; }
        public List<Thursday> Thursday { get; set; }
        public List<Friday> Friday { get; set; }
        public List<Saturday> Saturday { get; set; }
        public List<Sunday> Sunday { get; set; }

    }
   public class Monday
    {
        public int days { get; set; }
    }
   public class Tuesday
    {
        public int days { get; set; }
    }
   public class Wednesday
    {
        public int days { get; set; }
    }
   public class Thursday
    {
        public int days { get; set; }
    }
   public class Friday
    {
        public int days { get; set; }
    }
   public class Saturday
    {
        public int days { get; set; }
    }
   public class Sunday
    {
        public int days { get; set; }
    }
    class Program
    {


        static void Main(string[] args)
        {

          Monthlst objmonth = new Monthlst();
          Wednesday wednes = new Wednesday();
          wednes.days = 5;
          objmonth.Wednesday.Add(wednes); // here i am getting error object not set to.... 
        }
  }
}

Here i am just create instance of my Monthlst class in main method and the object of wednesday class in list property of Monthlst object but why it show me error i dont know Is there any wrong thing i am doing or not please explain….

Thanks,
Raj

  • 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-06-08T08:45:12+00:00Added an answer on June 8, 2026 at 8:45 am

    Yes, you’re not initializing your properties. After construction, all of the Monthlst properties will be null. You need to create a list before adding to it. For example:

    Monthlst objmonth = new Monthlst();
    objmonth.Wednesday = new List<Wednesday>();
    Wednesday wednes = new Wednesday();
    wednes.days = 5;
    objmonth.Wednesday.Add(wednes);
    

    Alternatively, make the constructor for Monthlst initialize all its properties.

    Aside from that, I think the design is somewhat ropy in various ways, but that’s a different matter.

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

Sidebar

Related Questions

I'm trying to create a reusable component to display some photo collection. The basic
Trying to create a list to return some JSON data to a view. Following
im getting the Object reference not set to an instance of an object for
I have created a custom collection class that I am trying to bind to
I'm trying to create a custom component with a collection property. However if I
I'm trying to create some classes that allow me to retrieve and manipulate a
Let's say an Owner has a collection of Watch(es). I am trying to create
I have been trying to create a web service out some python scripts, and
I'm trying to create some primitive imitation of the Windows Metro style application. What
I am trying to create a class to send multiple http request simultaneously on

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.