Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8704787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:11:51+00:00 2026-06-13T03:11:51+00:00

I need to define two methods for returning the sum and average of an

  • 0

I need to define two methods for returning the sum and average of an int array. The method defining is as follow:-

public int Sum(params int[] customerssalary)
{
           
         // I tried the following but it fails   return customerssalary.sum();
}

Another question is, how can I return the average of these int values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:11:53+00:00Added an answer on June 13, 2026 at 3:11 am

    This is the way you should be doing it, and I say this because you are clearly new to C# and should probably try to understand how some basic stuff works!

    public int Sum(params int[] customerssalary)
    {
       int result = 0;
    
       for(int i = 0; i < customerssalary.Length; i++)
       {
          result += customerssalary[i];
       }
    
       return result;
    }
    

    with this Sum function, you can use this to calculate the average too…

    public decimal Average(params int[] customerssalary)
    {
       int sum = Sum(customerssalary);
       decimal result = (decimal)sum / customerssalary.Length;
       return result;
    }
    

    the reason for using a decimal type in the second function is because the division can easily return a non-integer result


    Others have provided a Linq alternative which is what I would use myself anyway, but with Linq there is no point in having your own functions anyway. I have made the assumption that you have been asked to implement such functions as a task to demonstrate your understanding of C#, but I could be wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is there a need to define a new method in RESTful controller, follow
I need to define a get method in two different ways. One for simple
in bash I need to compare two float numbers, one which I define in
I need to define the constant in the module that use the method from
There are two kinds equals methods? public boolean equals(Bigram b) { return b.first ==
I need to know the difference between the following two methods of url connection?
When I need to define my own Equals method usually I only override Equals(Object)
In java we call it overloading when we define two methods with different numbers
I need to calculate the direction between two geolocation points (lat and log defined).
I need to define a Structuring Element of a mask size 30 by 105

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.