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

  • Home
  • SEARCH
  • 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 137107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:03:15+00:00 2026-05-11T07:03:15+00:00

I have a method like: AverageAndDoSomeMath (Point2) and I wonder how to handle: AverageAndDoSomeMath

  • 0

I have a method like:

AverageAndDoSomeMath (Point2) 

and I wonder how to handle:

AverageAndDoSomeMath (Point2) // single AverageAndDoSomeMath (Point2 collection) // multiple 

using a single implementation preferably.

For collection, I plan to use the IEnumerable type so I can pass any kind of collection, but for a single value, I don’t want to wrap and pass it as a collection, because the collection itself serves no purpose, other than to satisfy the type.

How to best handle it in the clearest, fastest, most efficient way?

EDIT: Maybe I should have chosen a better method name, but the method calculates the average of all the points, for 1 value it doesn’t make sense, but think of it as that the value will be used to say calculate another value, but what’s important is finding the average, so I can’t call the 1st method.

  • 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. 2026-05-11T07:03:15+00:00Added an answer on May 11, 2026 at 7:03 am

    I know you said you didn’t want to wrap it and pass it as a collection, but there are two ways you can do this with minimal hassle, so I’ll post them in case you weren’t aware of one.

    You could use params on your method:

    public void Average(params Point2[] points) 

    after which you can call it with any number of arguments, or with an array:

    Average(P1); Average(P2, P3, P4); Average(); // this one becomes an empty array in the method  Point[] array = new Point[] { P1, P2, P3, P4 }; Average(array); 

    Or alternately, you can use short array syntax to wrap up your object:

    Average({ P1 }); // this is legal C# for making an array with 1 element 

    EDIT: After reading your note, I would suggest that a params array is the clearest way to do what you want. The only real downside to it is that you can’t pass in an IEnumerable<Point2> (or other collections like a List<Point2>) without first calling ToArray(), because it only takes actual arrays.

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

Sidebar

Related Questions

Suppose I have a method like so: public byte[] GetThoseBytes() { using (System.IO.MemoryStream ms
I have a method like this: public List<Fruit> Traverse (IEnumerable<Fruit> collection, Action<Fruit> action) I
I have a method in a rails helper file like this def table_for(collection, *args)
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
If I have a method like this: public void DoSomething(int Count, string[] Lines) {
In a multithreaded scenario, I have a method like this: bool WaitForChange( time_duration WaitTime
I have wriiten a method like this public ArrayList<T> GetDoctorDetail(String name) { if (name!=null
If you have a controller method like so: @expose(json) def artists(self, action=view,artist_id=None): artists=session.query(model.Artist).all() return
If I have a method signature like public string myMethod<T>( ... ) How can
Let's say we have a method signature like public static function explodeDn($dn, array &$keys

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.