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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:48:49+00:00 2026-06-10T14:48:49+00:00

Possible Duplicate: C# – Reference type still needs pass by ref? class OutReturnExample {

  • 0

Possible Duplicate:
C# – Reference type still needs pass by ref?

class OutReturnExample
{
    static void Method(out int i, out string s1, out string s2)
    {
        i = 44;
        s1 = "I've been returned";
        s2 = null;
    }
    static void Main()
    {
        int value;
        string str1, str2;
        Method(out value, out str1, out str2);
        // value is now 44
        // str1 is now "I've been returned"
        // str2 is (still) null;
    }

I am new to C# and learning out modifier. I came across this snippet on MSDN.

I understand out is useful here for int primitive variable, but for string variables, references will be passed to the called method even without the out modifier, right?

  • 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-10T14:48:51+00:00Added an answer on June 10, 2026 at 2:48 pm

    references will be passed to the called method even without the out modifier, right?

    Yes, but without out they will not be passed back:

    void M(string s1, out string s2)
    {
        s1 = "one";
        s2 = "two";
    }
    
    void Main()
    {
        string s = "hello", t = "world";
        // s = "hello"
        // t = "world"
        M(s, out t);
        // s = "hello"
        // t = "two"
    }
    

    string is designed as immutable. You are probably thinking about mutable reference types:

    class Person { public string Name { get; set; } }
    
    void Main()
    {
        var p = new Person { Name = "Homer" };
        // p != null
        // p.Name = "Homer"
        M2(p);
        // p != null
        // p.Name = "Bart"
    }
    
    void M2(Person q)
    {
        q.Name = "Bart";   // q references same object as p
        q = null;          // no effect, q is a copy of p
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: C#: How to reference generic classes and methods in xml documentation I
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicate: Simple and clean xml manipulation in PHP I trying to reference specific
Possible Duplicate: Going crazy here, can't figure out why rename(), copy() functions don't work.
Possible Duplicate: how to add a reference to the system.data.SQLite.dll to the windows phone
Possible Duplicate: Find out the instance id from within an ec2 machine I am
Possible Duplicate: Create Generic method constraining T to an Enum Is there any reason
Possible Duplicate: How do I trim a string in javascript? By using replace method
Possible Duplicate: How to call base.base.method()? I have some trouble with Inheritance in C#.

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.