Pass arrays to a function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smileyc
    New Member
    • May 2009
    • 5

    Pass arrays to a function

    Hi, I have an array of integers and I want to pass the array to a function that will add up the elements of the array and return the cumulative total of the elements of the array. So, if the array contains the values {1,2,3,4,5} the return value from the function would be 15. How do I achieve that please.

    Thanks for all and any help.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    You'll have to convert my C# but that's not too tough

    Define your integer array.
    Code:
     int[] myIntArray;
    Give it values.
    Code:
     myIntArray[0] = 1;
     myIntArray[1] = 2;
     myIntArray[2] = 3;
    Pass it to your method while expecting a return

    Code:
    int nSolution = MyAdditionMethod(myIntArray);

    Comment

    • smileyc
      New Member
      • May 2009
      • 5

      #3
      It works great! Many thanks

      Comment

      Working...