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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:08:57+00:00 2026-05-27T17:08:57+00:00

I didnt know how to word the question, so sorry if it doesnt really

  • 0

I didnt know how to word the question, so sorry if it doesnt really make sense, but it should start making sense here. Also, I am sorry if the solution is really, really simple. Google couldnt understand what I was asking (probs cause I was asking it wrong :P)

So I wrote a class that I called OrderSelection

In my program I need to have an array of OrderSelection objects, and I need to perform actions on this array (re-ordering, sorting etc).

What I am doing right now is keeping methods in the OrderSelection class that accept, among others, the array which you want to re-order, for example.

something like:

public void reorder(OrderSelection[] ord, int switchX, int switchY){....}

But What I want to be able to do is this:

OrderSelection[] order = new OrderSelection[10];
//do stuff
order.reorder(1,2);//which is WAY better than order[0].reorder(order, 1,2) as a horrid example

So yeah…how can I add these functions which I want to apply to an array of objects of my class?

thanks!

  • 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-27T17:08:58+00:00Added an answer on May 27, 2026 at 5:08 pm

    You’re looking for Extension Methods. Here’s the MSDN documentation.

    Writing an extension method looks like this:

    public static class OrderSelectionExtensionMethods
    {
        public static void reorder(this OrderSelection[] orders, int x, int y) 
        {
            // Do something with each order
        }
    }
    

    Extension methods are usually defined in an entirely separate class.
    Also, two things are required for Extension Methods:

    • The entire class must be static
    • The first parameter for each extension method must have the keyword this before it

    With the above code, your example code would compile fine:

    OrderSelection[] order = new OrderSelection[10];
    //do stuff
    order.reorder(1,2);
    

    This is the exact same as writing the following:

    OrderSelection[] order = new OrderSelection[10];
    //do stuff
    OrderSelectionExtensionMethods.reorder(order, 1, 2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i didn't really know how to title this question, but here's a thing that
I know that title didn't make sense, Im sorry! Its hard to word what
Sorry about the vague title, but i didnt know how to ask the question
Ok, I didn't really know how to even phrase the question, but let me
i really didnt know how to word the title so i did the best
Hey all, title may be abit misleading but i didnt know the correct way
this is probably something I should know, but I'm puzzled by this. I'm trying
I know this question has been asked before but the other solutions didn't work
I don't know how to summarize my situation, but here's the simplified code showing
Sorry for this misleading subject, i didn't know how to word better. Because i'm

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.