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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:23:56+00:00 2026-06-13T03:23:56+00:00

In C#, I know that by default, any parameters passed into a function would

  • 0

In C#, I know that by default, any parameters passed into a function would be by copy, that’s, within the function, there is a local copy of the parameter. But, what about when an object is passed as parameter to another class?

Would a scenario like the following one be passed by reference or by value:

class MyClass {
   private Object localObj;

   public void SetObject(Object obj) {
      localObj = obj;
   }
}

void Main() {
   Object someTestObj = new Object();
   someTestObj.name = "My Name";
   MyClass cls = New MyClass();
   cls.SetObject(someTesetObj);
}

In this case, would the class variable localObj be having the same copy as the someTestObj created in the Main driver class? Or would the two variables be pointing to a different object instance?

  • 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-13T03:23:57+00:00Added an answer on June 13, 2026 at 3:23 am

    Objects will be passed by reference irrespective of within methods of same class or another class. Here is a modified version of same sample code to help you understand. The value will be changed to ‘xyz.’

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        public class Employee
        {
            public string Name { get; set; }
        }
    
        public class MyClass
        {
            public Employee EmpObj;
    
            public void SetObject(Employee obj)
            {
                EmpObj = obj;
            }
        }
    
        public class Program
        {
           static void Main(string[] args)
            {
                Employee someTestObj = new Employee();
                someTestObj.Name = "ABC";
    
                MyClass cls = new MyClass();
                cls.SetObject(someTestObj);
    
                Console.WriteLine("Changing Emp Name To xyz");
                someTestObj.Name = "xyz";
    
                Console.WriteLine("Accessing Assigned Emp Name");
                Console.WriteLine(cls.EmpObj.Name); 
    
               Console.ReadLine();
           }       
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that multiple parameters can be passed to COALESCE , but when you
I know that variables in F# are immutable by default. But, for example in
I know mongrel is the default server for script/server but when I do that
I know that I can declare delegates that have default constant parameters such as:
I know that component-model indicates whether a property has a default value or not,
I know that user accounts in Windows 7 are limited by default, so a
Does anybody know how to disable the default CKEditor behavior that changes the RichCombo
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I would like to know, when someone gives you a template for a default

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.