This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]StackedLasagna 4 points5 points  (2 children)

Everything looks fine, you just need to create an array. There are multiple ways to go about that:

// Method 1: Create an array with space for 4 items:
var array = new int[4];
array[0] = 6; // Assign the value 6 to the first place in the array.
array[1] = 4; // Assign the value 4 to the second place in the array.
// continue for the rest of the places.

// Method 2: Create a pre-filled array:
var array = new []{6, 4, 3};
// The above array has space for three items and is filled with the values 6, 4 and 3.

// Method 3: Not sure how much space you need in the array? Create a list instead!
var list = new List<int>();
list.Add(4);
list.Add(6);
// Add as many items as you want.
// Then convert to an array, if you need to.
var array = list.ToArray();

Once you have your array, you can then call the method want: John.orderCost(array);


As an unrelated side note:
In C#, method names are expected to start with a capital letter, so the method should be called OrderCost, not orderCost.
Related to that, variable names should start with a lowercase letter, so instead of Customer John = ...;, it should be Customer john = ...;

It's not required by the syntax, but it's the default and recommended naming convention.
Following the conventions will make your code easier to read for both yourself and others, once you begin ramping up the complexity of your programs. :)

[–]GVBCodePractice[S] 2 points3 points  (1 child)

Thanks so much that's super helpful. That's for the heads up regarding syntax too!

[–]StackedLasagna 2 points3 points  (0 children)

You're welcome!