How to Pass an Object as an Argument into Method in C#? Last Updated : 06 Dec, 2021 Comments Improve Suggest changes Like Article Like Report Given an object, now we pass this object as an argument into the method in C#. Here, a method is a code block that contains a series of statements that will only execute when the method is called. We can pass the data to the methods in form of arguments and an object is an instance of a class that is created dynamically. The basic data types can be passed as arguments to the C# methods in the same way the object can also be passed as an argument to a method. But keep in mind that we cannot pass a class object directly in the method. We can only pass the reference to the object in the method. // Creating the demo object demo d1 = new demo(6); // Passing object as an argument to the PassObj method. d1.PassObj(d1);Example 1: C# // C# program to pass an object as an argument into method using System; // Creating a class named demo class demo { int value; // Constructor to initialize the variable value public demo(int val) { value = val; } // Method in which we pass the object as a argument public void PassObj(demo d2) { Console.WriteLine(d2.value); } } // Driver code class GFG{ static void Main() { // Creating the demo object demo d1 = new demo(6); // Passing object as an argument to // the PassObj method. d1.PassObj(d1); } } Output6Explanation: In the above example, first we create a class named "demo" with a constructor to initialize an integer variable. It also has a method named PassObj() which takes one parameter. Now in the main function, we create an object of demo class named "d1" and then pass this object in PassObj() method, and the value is printed. Example 2: C# // C# program to pass two objects as an argument into method using System; class Geeks { int num; // Constructor to initialize the variable value public Geeks(int val) { num = val; } public void PassObj(Geeks d1, Geeks d2) { // Multiplying the values of both objects Console.WriteLine(d1.num * d2.num); } } // Driver code class GFG{ static void Main() { // Creating the demo objects Geeks d1 = new Geeks(6); Geeks d2 = new Geeks(2); // Passing 2 objects as arguments to the // PassObj method and PassObj will print // the product of the two values in the // two objects d1.PassObj(d1, d2); } } Output12Explanation: In the above example, first we create a class named "Geeks" with a constructor to initialize an integer variable. It also has a method named PassObj() which takes two parameters and returns the product of two values. Now in the main function, we create two objects of the Geeks class named "d1" and "d2" and then pass this object in PassObj() method, and the value is printed. Comment More infoAdvertise with us Next Article How to Pass Object as Parameter in JavaScript ? P pulamolusaimohan Follow Improve Article Tags : C# CSharp-OOP Similar Reads How to Pass Object as Parameter in JavaScript ? We'll see how to Pass an object as a Parameter in JavaScript. We can pass objects as parameters to functions just like we do with any other data type. passing objects as parameters to functions allows us to manipulate their properties within the function. These are the following approaches: Table of 3 min read Define and Call Methods in a Python Class In object-oriented programming, a class is a blueprint for creating objects, and methods are functions associated with those objects. Methods in a class allow you to define behavior and functionality for the objects created from that class. Python, being an object-oriented programming language, prov 3 min read Object.MemberwiseClone Method in C# with Examples Object.MemberwiseClone Method is used to create a shallow copy or make clone of the current Object. Shallow copy is a bit-wise copy of an object. In this case, a new object is created and that object has an exact copy of the existing object. Basically, this method copies the non-static fields of the 3 min read How to Call a Method in Java? In Java, calling a method helps us to reuse code and helps everything be organized. Java methods are just a block of code that does a specific task and gives us the result back. In this article, we are going to learn how to call different types of methods in Java with simple examples.What is a Metho 4 min read String.Format() Method in C# with Examples | Set - 1 In C#, Format() is a method of the String Class. This method is used to replace one or more format items in the specified string with the string representation of a specified object. In other words, this method is used to insert the value of the variable or an object or expression into another strin 4 min read String.Format() Method in C# with Examples | Set â 2 In C#, Format() is a string method. This method is used to replace one or more format items in the specified string with the string representation of a specified object.In other words, this method is used to insert the value of the variable or an object or expression into another string. This method 4 min read Like