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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:02:17+00:00 2026-06-15T19:02:17+00:00

Say I have a function: static void foo(int[,] arr, arg1) { //say arg1 =

  • 0

Say I have a function:

static void foo(int[,] arr, arg1)
{
    //say arg1 = row - 1

    for(int row = 0; row < arr.GetLength(0); row++)
    {  
         for(int col = 0; col < arr.GetLength(1); col++)
         {
             MessageBox.Show(arr[arg1 , col]) // should be equal to arr[row-1,col]
         }
    }
}
foo(arr, "row-1"); // should be equal to arr[row-1,col]

I want to reference the loop variable with arg1.
Is this possible?
What type should arg1 be?
How do i write this?

  • 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-15T19:02:19+00:00Added an answer on June 15, 2026 at 7:02 pm

    You would do this by passing Func<int,int> to the function:

    static void foo(int[,] arr, Func<int,int> arg1)
    {
        //say arg1 = row - 1
    
        for(int row = 0; row < arr.GetLength(0); row++)
        {  
             for(int col = 0; col < arr.GetLength(1); col++)
             {
                 int newRow = arg1(row);
                 MessageBox.Show(arr[newRow, col]) // should be equal to arr[row-1,col]
             }
        }
    }
    

    Then call it with a lamda which represents the transformation you want to do.

    foo(arr, x => x-1);
    

    The problem with this approach is that the first iteration round row it will have the value 0. By subtracting 1 from this you try to get arr[-1,col] which is outside of the bounds of the array. Im not sure what you’re trying to actually achieve, so I can only guess that either you want to start the row variable at 1:

    for(int row = 1; row < arr.GetLength(0); row++)
    

    or perhaps a more complex rule for the lambda:

    foo(arr, x => x>0 ? x-1 : 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following signature: static extern void External(int foo, IntPtr bar);
Say I have this small function in a source file static void foo() {}
Say I have a function pointer in C- library int (*fptr)(void); And I have
Say I have a function foo: (defun foo (x y &rest args) ...) And
Say I have a function foo that I want to call n times. In
Let's say I have following code: int f() { int foo = 0; int
Say I have: class A { public: static void DoStuff(); // ... more methods
Here is my problem: I have the function public static void fillObject(object [] obs,
I have this function: public static int checkRank(String lineToCompare){ int rank = 0; try{
Let's say I have a simple function like this: public static string randomthing(string var1)

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.