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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:53:42+00:00 2026-05-20T02:53:42+00:00

What I have here are two methods (killZombie) that handle cases where you have

  • 0

What I have here are two methods (killZombie) that handle cases where you have one argument (string) or more than one argument (string[]). Because they do the same thing, I made another method named “killAZombie” that is used by the other two methods. The problem I’m having is that the method “killAZombie” is named… well kind of strangely. Is this a problem that other people encounter too? What is the best way to solve this and name my “KillAZombie” method something else that distinguishes itself more clearly from “killZombie”

public void killZombie(string zombieLocation){
    killAZombie(zombieLocation);
}

public void killZombie(string[] zombieLocations){
    foreach(string zombieLocation in zombieLocations){
        killAZombie(zombieLocation);
    }
}

public void killAZombie(string zombieLocation){
    //Kills a zombie at specified location
}

Another way I can see this problem being solved is by instead of overloading “killZombie” have two different methods like this:

public void killZombie(string zombieLocation){
    //Kills a zombie at specified location
}

public void killZombies(string[] zombieLocations){
    foreach(string zombieLocation in zombieLocations){
        killZombie(zombieLocation);
    }
}

This way we only have two methods that are easier to understand, but then the method isn’t overloaded. In my mind, it seems like a good thing to have overloaded methods (this just means there are fewer methods, less clutter) so I’m not sure about this solution either. I’d be interested in hearing what would be the best way to tackle this problem, thanks!

Addendum:

My method actually takes 4 arguments, so the params will be at the end. The params variable is the most important one, so putting it as the last argument to make the params work seems kind of clunky. Is my concern over putting the most important argument last, legitimate enough to split up the methods into KillZombie and KillZombies or is the params still the right way to do things?

  • 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-20T02:53:43+00:00Added an answer on May 20, 2026 at 2:53 am

    The latter of your two choices is probably preferable in this case (given that the naming of the function implies that it’s operating upon a single “zombie”.

    However, you might also want to look into the params keyword, just so you know what your options are. For instance, if you’d named your function simply Kill (and if it made sense to do so in this context), you could have:

    public void Kill(params string[] zombieNames)
    {
        foreach(string name in zombieNames)
        {
    
        }
    }
    

    And you could call it a number of ways:

    Kill("Zoey");
    Kill("Francis", "Zoey");
    
    string[] survivors = { "Zoey", "Francis", "Bill", "Louis" };
    
    Kill(names);
    

    (Assuming, of course, that your survivors had all been turned into zombies!)

    Also, stylistically C# code generally uses pascal casing for function names (KillAZombie rather than killAZombie).

    Edit for Addendum

    Yes, parameter ordering–while it has no technical relevance–is an important consideration in API design, so if you’re going to be taking “less important” parameters, then you’ll probably have to do without params.

    With that said, I’ll stand by my original recommendation: as the function is named (KillZombie versus Kill), I would stick with two versions just for the sake of making your name consistent with the parameters. I would also suggest allowing the user to specify IEnumerable<string> instead of an array. That will allow the developer to pass the names using anything that implements IEnumerable<string>, including a string array.

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

Sidebar

Related Questions

I have a script that appends some rows to a table. One of the
This is beyond both making sense and my control. That being said here is
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a new web app that is packaged as a WAR as part
Let say I have the following desire, to simplify the IConvertible's to allow me
I have found this example on StackOverflow: var people = new List<Person> { new
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
I have a login.jsp page which contains a login form. Once logged in the
There doesn't seem to be any tried and true set of best practices to

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.