Praveen Kumar

Praveen Kumar

  • 258
  • 6.6k
  • 2.3m

Object Instantiation in C# Programming

Jul 6 2017 1:13 AM
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.   }  
 

Answers (3)