3
Reply

Object Instantiation in C# Programming

Praveen

Praveen

Jul 6 2017 1:13 AM
326
Object Instantiation in C# Programming
 
I have a class Greet and I am creating a object of this class by following two ways. Could you suggest me, which one is best way or both are same from the memory allocation point of view.  
 
Kindly suggest the answer from the memory allocation point of view 
  1. class Greet  
  2. {  
  3.     public string SayHello()  
  4.     {  
  5.         return "Hello Praveen";  
  6.     }  
  7. }  
  1. static void Main(string[] args)  
  2.   {  
  3.       string message = "";  
  4.       //1. First Way  
  5.       Greet greet = new Greet();  
  6.       message=greet.SayHello();  
  7.   
  8.       //1. Second Way              
  9.       message =new Greet().SayHello();  
  10.   }  
 

Upload Source Code  Select only zip and rar file.
Answers (3)