Class instantiate

Hi,
I’ve a proble using a class …

public class Vehicle

{

    private int clientIdField;

    public int clientId

    {

        get

        {

        return this.clientIdField;

        }

        set

        {

        this.clientIdField = value;

    }

}

In main I try this :

Vehicle fre = new Vehicle[10];

it’s ok But with :

fre[0].clientId = 1;

I’va an error … about no object instant existing…

An idea ?

Really thaks !

Hi,

Creating the new array, with a size of 10, doesn’t actually create the instances for each indexes.

so, you simply need to check if the instance is null and then create it, else work with it. Like so for ( a ruff ) example:

Vehicle[] fre = new Vehicle[10];
	
	if ( fre[0] ==null)
	{
		fre[0] = new Vehicle();
	}
	
	fre[0].clientId = 1;

Hope this helps,

Bye,

Jean