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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:47:09+00:00 2026-06-15T18:47:09+00:00

I know some codes here are not clear. I’m still in the process of

  • 0

I know some codes here are not clear. I’m still in the process of trying out things. I’ve got three questions, why does an error shows up when adding a string in my list? How do I pass the List in Class1 to my main class? And is my syntax correct in List passArr? Not sure if I should add parenthesis at the end of passArr.

class Class1
{
    public static List<string> passArr
    {
        get;
        set;
    }

    public static void passIt()
    {
        passArr.Add("A"); //Error: Object reference not set to an instance of an object
    }
}

Main Class

class Program
{
    static void Main(string[] args)
    {
        Class1.passIt();
        List<string> passArr1 = Class1.passArr;
        foreach (string s in passArr1)
        {
            Console.WriteLine(s);
        }
        Console.ReadLine();
    }
}
  • 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-15T18:47:10+00:00Added an answer on June 15, 2026 at 6:47 pm

    You’re never creating a list, so the passArr property (which needs renaming, by the way) always has a value of null. You need something like:

    Class1.passArr = new List<string>();
    

    at some point. Another alternative would be to make it a read-only property backed by a field with an initializer:

    private static readonly List<string> passArr = new List<string>();
    public static List<string> PassArr { get { return passArr; } }
    

    (This complies with naming convention in terms of case, but it’s still not a meaningful name, of course.)

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

Sidebar

Related Questions

I'm trying to understand some MATLAB source codes. I don't know exactly which one
I am trying to generate some code using CodeDom. I wanted to know if
I meet some scala code with ? but do not know what it mean
I'm trying out something here with floating the boxes in a container. The problem
Here's some code I've got in my sandbox.php file: <div class=jq> <img class=active id=also
I have some code that I know could be nicer if it's done in
I had to de-compile some code and I don't know what this syntax is?
I was looking at some code in Python (I know nothing about Python) and
Does anyone know how to or have some code on counting the number of
I'm implementing some code generators, i would like to know if there's any way

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.