Nick 879
Nick 879

Reputation: 130

Returning an instance of a class

Any pointers on this one would be gratefully received. I have a public class called Values.

In a public method I create a new instance, and then do a bunch of work to fill up testValues. I'd then like to return the filled testValues, but I can't find a syntax that works.

public static Values  MethodToCalcIRR()
{
    Values[] testValues = new Values[200];
    // Work
    return testValues;
}

gives me an error, where Investments_4 is the namespace for the whole solution:

Cannot implicitly convert type 'Investments_4.Values[]' to 'Investments_4.Values'

This approach:

return testValues[];

makes the reasonable complaint that I haven't specified which rows I want.

Any help gratefully received, and my apologies if I've got a fundamental misunderstanding of what's possible here. My programming level is still reasonably basic so it's entirely possible.

Upvotes: 0

Views: 65

Answers (1)

CodeCaster
CodeCaster

Reputation: 151588

[] denotes an array. Your return type is a singular item, not an array. Change your return type to be an array:

public static Values[] MethodToCalcIRR()

Upvotes: 5

Related Questions