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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:45:25+00:00 2026-05-18T03:45:25+00:00

Can anyone explain the behaviour of the below code. The output of the below

  • 0

Can anyone explain the behaviour of the below code. The output of the below code is string “str” and i’s value is 100.

But why is it so? After setting object c1 = null, why isn’t it null?

public class Class1
{
    public int i;
    public Class1()
    {
        i = 10;
    }    

    public string method1()
    {
        return "str";
    }
}

public class Class2
{
    public void method2(Class1 c1)
    {
        c1.i = 100;
        c1 = null;
    }
}

    void main()
    {
        Class1 c1 = new Class1();
        Class2 c2 = new Class2();
        c2.method2(c1);
        Response.Write(c1.method1());
        Response.Write(c1.i.ToString());
    }
  • 1 1 Answer
  • 1 View
  • 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-18T03:45:26+00:00Added an answer on May 18, 2026 at 3:45 am

    This is a pass-by-reference/pass-by-value thing. Javaranch Camp site stories: Pass By Value Please explains it very well. I know the above link is for Java, and this is a C# question, but the same thing happens (unless the “ref” keyword is used).

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

Sidebar

Related Questions

Can anyone explain the following behaviour to a relative newbie... const char cInputFilenameAndPath[] =
Can anyone explain to me why, in VBA code for a button on a
Can anyone explain this code to me? Whats the meaning and how to use
Can anyone explain why this code: {% form_theme form _self %} {% block avo_gallery_upload_widget
Can anyone explain this behaviour? var culture = new CultureInfo(da-DK); Thread.CurrentThread.CurrentCulture = culture; daab.StartsWith(da);
Can anyone explain this OCaml toplevel behaviour? # 1________________________________1;; - : int = 11
Can anyone explain how best to emulate the behaviour the accessory view ( in
Can anyone explain the following behaviour to me? When a field type in an
Can anyone explain this strange behaviour in jQuery? I'm using version 1.5.2. var myxml
Can anyone explain to me why this program: for(float i = -1; i <

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.