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 181803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:49:40+00:00 2026-05-11T14:49:40+00:00

Let say I got this function : void int Calculate(double[] array) {} And in

  • 0

Let say I got this function :

void int Calculate(double[] array) {} 

And in my main I got this array:

double[,] myArray = new double[3,3]; 

How can I call Calculate(…) ?

I try (that’s don’t compile) :

double[] mySingleArray = myArray[0]; 

What I want to avoid is unnecessary loop (for).

I declare a regular array, but if a jagged array or any other type of array works better, it’s fine for me.

I use c# 3.5

  • 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-11T14:49:41+00:00Added an answer on May 11, 2026 at 2:49 pm

    First, let’s declare your Calculate() method like this:

    int Calculate(IEnumerable<double> doubles) 

    Don’t worry, you can still pass an array to that code. You might also need IList<double>, but 9 times out of 10 the IEnumerable is good enough. The main thing is that this will let us use the yield keyword to slice up your array in an efficient way:

    public static IEnumerable<T> Slice(this T[,] values) {     return Slice(values, 0, 0); }  public static IEnumerable<T> Slice(this T[,] values, int index) {     return Slice(values, 0, index); }  public static IEnumerable<T> Slice(this T[,] values, int dimension, int index) {     int length = values.GetUpperBound(dimension);     int[] point = new int[values.Rank];     point[dimension] = index;     dimension = 1 - dimension;// only works for rank == 2     for (int i = 0; i < length; i++)     {         point[dimension] = i;          yield return (T)values.GetValue(point);     } } 

    It still needs some work because it only works with rank 2 arrays, but it should be fine for the example you posted.

    Now you can call your calculate function like this:

    Calculate(myArray.Slice(0)); 

    Note that due to the way IEnumerable and the yield statement work the for loop in the code I posted is essentially free. It won’t run until you actually iterate the items in your Calculate method, and even there runs in a ‘just-in-time’ fashion so that the whole algorithm remains O(n).

    It gets even more interesting when you share what your Calculate method is doing. You might be able to express it as a simple Aggregate + lambda expression. For example, let’s say your calculate method returned the number of items > 5:

    myArray.Slice(0).Count(x => x > 5);   

    Or say it summed all the items:

    myArray.Slice().Sum(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 206k
  • Answers 206k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A %20 is a URL encoded space character. Because a… May 12, 2026 at 9:08 pm
  • Editorial Team
    Editorial Team added an answer I think it is not possible in Criteria, it has… May 12, 2026 at 9:08 pm
  • Editorial Team
    Editorial Team added an answer In Karmic, you can just use the add-apt-repository command, at… May 12, 2026 at 9:08 pm

Related Questions

Hehe I'm having hard time on choosing the question title. But let me explain
I'm trying to learn how to create a C/C++ library in a linux environment
Let me first say that I've got a fair amount of experience in both
I've got a philosophical programming problem. Let's say I have a class named Employees.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.