Object And Refrence

Object And Refrence

When you are thinking about .net Think about object.

scenario you have initiated an object of user profile in some layer and returning it to main.

e.g.

public class xxx
{

   public static UserProfile GetUserProfileByID(long id)
   {
    UserProfile u = new UserProfile();

    // some code to populate user profile object

    return u;

   }
}
 


Above method when called returns object of UserProfil. So many users accept it like below

UserProfile user = new UserProfile()      //  Don;t instantiate new instance as you your method is returning new instance for you.
user = xxx.GetUserProfile(); 


correct way is simply referto already instantiated object no need to create multiple instances.

UserProfile user = xxx.GetUserProfile();
 

This makes sense. Isn''t it ?

Tags:

Asp.net Cache Objectsession objectscache object nullCould not allocate space for object dboSORT temporary run storageSessions In AspnetGridview select emailC# Read CSV Filegridview add new rowGC in dot netHack WiFi NetworkC# Arraylist foreach

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.