Language isn't obvious. In most languages (C++, C#, Java) you are to return specific type; even if this is "general" type like void* or object, you usually have to know which methods of it you can and can't call at compile-time. Workarounds are possible, but in your case, they probably aren't needed.
What you do need is Factory or Abstract Factory pattern, I suppose. You have to figure out what is general interface for all possible cases (because if function can return either int or array, you can't add returned values, neither you can take their elements) and implement this interface in different classes. Then, whenever you need to create instance of interface, you request Factory to do that, and Factory chooses which class it should be.
interface ISampleValues{
public abstract int NumberOfValues();
public abstract int SpecificValue(int index);
}
class SingleValue : ISampleValues {
private int m_value;
public SingleValue(int val) {m_value = val;}
public override int NumberOfValues() {return 1;}
public override int SpecificValue(int index) {return m_value;}
}
class ArrayOfValues : ISampleValues {
private int[] m_values;
public ArrayOfValues(int[] arr) {m_values = arr.Clone();}
public override int NumberOfValues() {return m_values.Length;}
public override int SpecificValue(int index) {return m_values[index];}
}
class ValuesFabric {
public ISampleValues GetValues() {
if(System.Config.Multiple)
return new ArrayOfValues(System.Config.ValuesArray);
else
return new SingleValue(System.Config.ValuesArray[0]);
}
}