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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:59:25+00:00 2026-06-05T05:59:25+00:00

The methods below are just inverses of one another. I suspect that I can

  • 0

The methods below are just inverses of one another. I suspect that I can combine the logic into one method. I prefer to avoid Reflection. Is it possible to combine them and maintain readability?

    private void btnAdd_Click(object sender, EventArgs e)
    {
        LabEntity selectedItem = bindingSource1.Current as LabEntity;
        selectedLabsData.Add(selectedItem);
        availableLabsData.Remove(selectedItem);
    }

    private void btnRemove_Click(object sender, EventArgs e)
    {
        LabEntity selectedItem = bindingSource2.Current as LabEntity;//new binding source
        availableLabsData.Add(selectedItem);//called Add instead of remove
        selectedLabsData.Remove(selectedItem);//called Remove instead of Add
    }
  • 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-05T05:59:26+00:00Added an answer on June 5, 2026 at 5:59 am

    You could factor out the logic into a helper method:

    private void ListFixup(object entity, List<Item> addList, List<Item> removeList)
    {
        LabEntity selectedItem = entity as LabEntity;
        // don't forget your error checking here
    
        addList.Add(selectedItem);
        removeList.Remove(selectedItem);
    }
    
    private void btnAdd_Click(object sender, EventArgs e)
    {
        ListFixup(bindingSource1.Current, selectedLabsData, availableLabsData);
    }
    
    private void btnRemove_Click(object sender, EventArgs e)
    {
        ListFixup(bindingSource2.Current, availableLabsData, selectedLabsData);
    }
    

    I’m not sure this helps readability, but it does reduce code duplication.

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

Sidebar

Related Questions

I just read in a document that A static method can call only other
I just learned that I can overwrite a method in a Javascript class, as
Objects in C++ can be created using the methods listed below(that I am aware
I have a method somewhat similar to the one written bellow(this is just a
Below I call the same methods in author and w5 model objects. But one
The method below called UserCanAccessThisPage is based on the following logic: each user and
Below are two simple Cython methods I wrote. In g_cython() method I used additional
Edit: Two options shown below. If you're just using the functionality that an IDisposable
Being that properties are just methods under the hood, it's understandable that the performance
I am just thinking of the difference between below methods, while defining constants: Method1:

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.