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

  • Home
  • SEARCH
  • 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 3424028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:25:32+00:00 2026-05-18T06:25:32+00:00

hey i am trying to work with a generic list in C# and for

  • 0

hey i am trying to work with a generic list in C# and for some reason after allocating memory for the list i am getting unhandeledNullException.

 //edit

i found out what was my problem i did not use the properties currectly.
if lets say GeoInfo is a private member of my class, how do i do properties to it,
i tried :

 private List<GeoInfo> GEOINFOS { get; set; } // edit i forgot to change it back 
// but i want to have my geoinfos private and my properties public

thanks in advance for your help

  • 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-18T06:25:32+00:00Added an answer on May 18, 2026 at 6:25 am

    You’ve made the properties private. If you want them to be public try:

    public List<GeoInfo> GeoInfos { get; set; }
    

    The auto-implemented value that is stored locally in the object will be private; but the properties themselves are public.

    Because what you are declaring there are the property accessors.

    If you want to write everything explicitly, you could do it the old pre 3.0 way

    private List<GeoInfo> geoInfos = new List<GeoInfo>;
    public List<GeoInfo> GeoInfos {
      get { return geoInfos; }
      set { geoInfos = value; }
    }
    

    This still relies on geoInfos being initialized somewhere (like the constructor) — or nullPointerException will return.

    You could do lazy-evaluation on it right in the getter:

    private List<GeoInfo> geoInfos = new List<GeoInfo>;
    public List<GeoInfo> GeoInfos {
      get { if (geoInfos == null) {
              geoInfos = new List<GeoInfo>;
            } 
            return geoInfos; 
          }
      set { geoInfos = value; }
    }
    

    This ensures that you don’t have to specify a call in the constructor, and you don’t have to worry about the execution sequence setting the element explicitly prior to getting it.

    But if you use the auto-generated-properties, you will have to explicitly set the reference at some point. AS suggested elsewhere, the best bet is the constructor.

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

Sidebar

Related Questions

Hey, im trying to get an INSERT command to work, but I keep getting
Hey, I'm trying to work out what event I need to bind to and
Hey, have been trying to work this out for last day or so but
Hey guys, I'm trying to get threading to work in ASP.NET but for some
Hey I have a really annoying IE7 bug that I am trying to work
Hey all, here is the issue I am currently trying to work through. We
Hey guys i am trying to automate my system at work for sending artwork
Hey there, I am trying to get my signout button to work. This is
Hey having some trouble trying to maintain transparency on a png when i create
Hey i'm just trying to write some code in DrScheme: ((function (x) (* x

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.