Hi guys ) Please help me - I can't understand - what's the meaning of this error message .

Object reference not set to an instance of an object.

for this piece of code -

CityName = "NY";                         
this.MapCityMass.ArrayOfCities[this.NumberOfCities].CityName = CityName;

this class's code -

public class CITY
    {
        public int namber; 
        public string CityName;
        public int x; 
        public int y;
        public DinArray roadmass; 
        public DinArray roadnamesmass; 
    }

thank you in advance for your answers))

>Object reference not set to an instance of an object.

Meaning: An object is not created or you can say "An object is missing".

Array of city objects:

1. Declare an array variable

CITY []ar;

2. Create some object variables of type CITY. (Instantiate the array)

ar=new CITY[3];  // Three object variables of CITY type are created and each 
                  // variable has null value - null indicate "Missing object"

3. Create objects of CITY

//1st object of CITY 
ar[0]=new CITY();

//2nd object of CITY
ar[1]=new CITY();

//3rd object of CITY
ar[2]=new CITY();

Code of CITY Type must be:

public class CITY
    {
        public int namber;  
        public string CityName;          // object variable having "null"
        public int x; 
        public int y;
        public DinArray roadmass;       // object variable having "null"
        public DinArray roadnamesmass;  // object variable having "null"

        //Add constructor instantiate the DinArray
         public CITY() 
          {
              CityName=string.Empty;
              roadmass=new DinArray();
              roadnamemass=new DinArray();
           }    
    }
commented: ++++++ +1

thank you very much, adatapost ! ))
Now everything is clear) the problem is solved)

commented: Glad you got it working! thanks for rep :) +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.