Results 1 to 5 of 5

Thread: Passing object as a parameter in a method

  1. #1
    Join Date
    Dec 2010
    Posts
    49

    Passing object as a parameter in a method

    Hello my friends , I am working in a back office firm in a private firm , but I do not like this job profile at all , so I am opting to switch my profile and planning to make my career in the software development, so I have started a bit of programming and already finished with some basic programming , but when it comes to complex coding I find it difficult to manage , so I had one doubt. I am aware that we can pass arguments to the methods , but I wanted to know how and when do you pass objects in the parameter, I am a lot of expectation with this forum and if you explain it with the program, it will be an add on help.

  2. #2
    Join Date
    May 2009
    Posts
    539

    Re: passing object as a parameter in a method

    Now, let's look at the scenario where the method changes the object that the parameter references (for instance . the function creates a new SqlConnection and has the arguments reference it). If you do not make use of "ref" the function will make use of the newly created instance but the variable that the invoker passed as an argument will remain unaffected and continue to reference the actual object. If you do make use of "ref" keyword then the function will use the recently created instance and the variable that the invoker passed as an argument will also refer to this recently created object.

  3. #3
    Join Date
    Apr 2009
    Posts
    569

    Re: passing object as a parameter in a method

    Yes you can definitely pass objects as a parameter in a method in your program as you pass you do not require to make use of the ref keyword when passing objects as parameters, and under most situation you will not do this . When you give an object as a parameter a copy of the reference is passed to the function so you can still have control on the properties and properties of the object. I hope this might have cleared your doubt ,but if not let me know so that I can help you in better way.

  4. #4
    Join Date
    May 2009
    Posts
    527

    Re: passing object as a parameter in a method

    When we writing our program , we require quite often to pass a something as an argument in the method . There are different kind of variables can be passed, they can value type or they can also be of reference type, and in some scenarios they are immutable reference types, and they can be pass as dissimilar sorts of parameters (value or , reference parameter, C# also provides some special types of parameter as parameter array .I think you are quite aware that in C# by default the parameters are passed by value. But make a note that for a reference kind variable, mostly user see that as passed by reference by default. If asking the truth an object is passed by reference , but if you do not know what exactly happens is , the reference of the object is passed by value.

  5. #5
    Join Date
    May 2009
    Posts
    511

    Re: passing object as a parameter in a method

    Reference data type parameters, for example instances of the class are also passed into function by value. This implies that when the function returns, the passed-in reference still references the same instance as it was doing previously . However, the values of the instance 's fields can be altered in the function , if they possess the correct access level. I think the objects can also be passed in the Constructors parameter as well.

Similar Threads

  1. Passing an ArrayList From the Form as Parameter
    By Sheenas in forum Software Development
    Replies: 8
    Last Post: 20-06-2010, 10:45 AM
  2. Problem While Passing Parameter To Servlet In JSP
    By Jagdish Gada in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 02:33 PM
  3. Passing function parameter and static
    By Banjiji in forum Software Development
    Replies: 3
    Last Post: 27-10-2009, 07:32 PM
  4. Passing parameter of Oracle procedure in PHP
    By Halina in forum Software Development
    Replies: 3
    Last Post: 22-04-2009, 08:46 PM
  5. Parameter passing using NavigateURL
    By Sachit in forum Software Development
    Replies: 3
    Last Post: 26-03-2009, 09:25 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,166,239.41489 seconds with 17 queries