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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:42:08+00:00 2026-06-11T17:42:08+00:00

Given the following method: static void ChangeArray(params string[] array) { for (int i =

  • 0

Given the following method:

static void ChangeArray(params string[] array) {

    for (int i = 0; i < array.Length; i++) 
        array[i] = array[i] + "s";
}

This works if I call it passing a array of strings:

string[] array = {"Michael", "Jordan"} // will become {"Michaels", "Jordans"}
ChangeArray(array);

But will not work if I call it using string arguments:

string Michael = "Michael";
string Jordan = "Jordan";
ChangeArray(Michael, Jordan); // This will NOT change the values of the variables

I understand that the compiler will wrap Michael and Jordan on an array, so shouldn’t the results be the same on both cases?

  • 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-11T17:42:09+00:00Added an answer on June 11, 2026 at 5:42 pm

    Your second example is essentially:

    string Michael = "Michael";
    string Jordan = "Jordan";
    {
        var tmp = new string[] {Michael, Jordan};
        ChangeArray(tmp);
    }
    

    so; actually, the values inside tmp were changed… but tmp was discarded afterwards, so you don’t see anything. params does not emulate ref – it won’t do a position-wise update back into the original variables. Or in code, it is not the following:

    string Michael = "Michael";
    string Jordan = "Jordan";
    {
        var tmp = new string[] {Michael, Jordan};
        ChangeArray(tmp);
        Michael = tmp[0];
        Jordan = tmp[1];
    }
    

    If you need it to behave like that, then code it like that – or use instead an overload that takes ref parameters.

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

Sidebar

Related Questions

Given the following method: public static void SetPropertyValue(object target, string propName, object value) {
Given the following method in Java: public static <U> void foo() { } Within
Given the following situation (UML below), If Y has the method: public void PrintWs();
I have the following methods: protected static void updateExistingSection(XmlDocument doc, XmlNode rootNode, string sectionTag,
Given the following code sample: public class WeirdStuff { public static int doSomething() {
How can I pass an array of filenames into the following method: public static
Given the following method signature, why is it when a parameter is explicitly named
Given the following two ways of defining a class method in Ruby: class Foo
Given the following module, module Foo def bar :baz end end def send_to_foo(method) #
It seems that the following is a common method given in many tutorials on

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.