error CS0119: I declared the variable, but it is saying I need to declare it.

Hey all. Was wondering if someone could take a look at my code to tell me what I’m doing wrong. I can’t figure it out and it should work, right?

I have polymorphic constructors for a class “ZoneRequirement”. It would prefer to declare with integer array, but I can use an integer and it should make it an integer array first then run the first constructor. The code is below:

using UnityEngine;
using System.Collections;

public class ZoneRequirement : ICompare {

private _SingleRequirement requirement;

public ZoneRequirement(int[] req){
    requirement = new _SingleRequirement (req);
}

public ZoneRequirement(int req){
    int[] temp = new int[] {req};
    ZoneRequirement (temp);
}
}

I am getting error, which would denote I am not declaring a variable for this line:

ZoneRequirement (temp);

error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected

This should work? I am declaring a variable. It is declared it isn’t a type! Right?? Does anyone see what I am doing incorrectly. An integer array isn’t a type, right?

Thanks.

I think that you’re getting that error because you’re trying to call a constructor like you would a method. You would probably be better off if you just changed your second constructor to something like this:

 public ZoneRequirement(int req)
 {
     requirement = new _SingleRequirement(new int[] { req });
 }