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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:41:44+00:00 2026-05-27T14:41:44+00:00

If this sounds too impossible, pls dont down vote :) Just my quirk that

  • 0

If this sounds too impossible, pls dont down vote 🙂 Just my quirk that I wonder if ever I can pass a property as the parameter to a function to get some result.

For eg.

void delete_button_click ()
{
    foreach (DataGridViewRow row in dgvRecords.SelectedRows)
        dgvRecords.Rows.Remove(row);
}

And suppose

void delete_all_button click ()
{
    foreach (DataGridViewRow row in dgvRecords.Rows)
        dgvRecords.Rows.Remove(row);
}

Can I write the above two codes in one function since the only difference is SelectedRows and Rows. Something like this:

void button_click (/*DataGridView property rows*/)
{
    foreach (DataGridViewRow row in dgvRecords.rows)
        dgvRecords.Rows.Remove(row);
}

And call it

{
   button_click(DataGridView.Rows);
   //and
   button_click(DataGridView.SelectedRows);
}

Another eg.,

decimal GetAmount1(User usr)
{
    decimal sum = 0;
    foreach (DataGridViewRow row in dgvRecords.Rows)
    {
        Tuple<User, User, Notification, Acknowledgment> tup = (Tuple<User, User, Notification, Acknowledgment>)row.Tag;
        if (tup.Item1 == usr)
            sum += tup.Item4.Sum;

    }
    return sum;
}

and

decimal GetAmount2(User usr)
{
    decimal sum = 0;
    foreach (DataGridViewRow row in dgvRecords.Rows)
    {
        Tuple<User, User, Notification, Acknowledgment> tup = (Tuple<User, User, Notification, Acknowledgment>)row.Tag;
        if (tup.Item2 == usr)
            sum += tup.Item4.Sum;

    }
    return sum;
}

The only difference in above codes are just a property. So is this available:

decimal GetAmount(User usr, Tuple<User, User, Notification, Acknowledgment>.Property Item)
{
    decimal sum = 0;
    foreach (DataGridViewRow row in dgvRecords.Rows)
    {
        Tuple<User, User, Notification, Acknowledgment> tup = (Tuple<User, User, Notification, Acknowledgment>)row.Tag;
        if (tup.Item == usr)
            sum += tup.Item4.Sum;

    }
    return sum;
}

And call :

{ 
     GetAmount(usr, Tuple<User, User, Notification, Acknowledgment>.Item1)
     //and
     GetAmount(usr, Tuple<User, User, Notification, Acknowledgment>.Item2)   
}

??

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

    Your first example is can be solved by just using a normal parameter:

    The signature of a method to remove rows would be:

    void RemoveRows (IList rows)
    {
        foreach (var row in rows)
            dgvRecords.Rows.Remove(row);
    }
    

    and call it with:

    RemoveRows (DataGridView.Rows);
    //or
    RemoveRows (DataGridView.SelectedRows);
    

    The second example requires the use of a Func<T, TResult> which allows you to define what property you want to select.

    So your GetAmount() method siganture becomes:

    decimal GetAmount(User usr, Func<Tuple<User, User, Notification, Acknowledgment>, User> selector)
    {
        decimal sum = 0;
        foreach (DataGridViewRow row in dgvRecords.Rows)
        {
            Tuple<User, User, Notification, Acknowledgment> tup = (Tuple<User, User, Notification, Acknowledgment>)row.Tag;
            if (selector(tup) == usr)
                sum += tup.Item4.Sum;
    
        }
        return sum;
    }
    

    and you would call it:

    GetAmount(usr, tuple => tuple.Item1);
    //or
    GetAmount(usr,  tuple => tuple.Item1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a patterns newbie so please excuse this question if it sounds too
This is going to sound too silly / too basic - sorry about that,
This sounds funny..just a little experiment. i wanted to simulate a drag drop of
This sounds ridiculously easy, and it is with other shells. But I can't seem
Cocoa newbie here... I know this sounds stupid but I can't find the Bindings
This question sounds too trivial, but I could not find the answer anywhere. I
I am a beginner, so, please bear with me, if this sounds too trivial.When
This sounds a bit too good to be true, so please tell me if
This sounds like a stupid question (to me), but I've searched and I can't
This sounds like a weird title and probably not stated too well. But here's

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.