Two Ways of Initializing a New Object in C#
Recently I posted a question about the different ways one can initialize an object in a C# class. I generally use EXAMPLE 1 below. Resharper suggests I use EXAMPLE 2. EXAMPLE 1 is more intuitive to me (since it is want I always use). However my friend FC pointed out he prefers to "
 though my tests tend not to have the serialization requirements facilitated by EXAMPLE 2 I will consider switching course for the sole value stated by FC.
EXAMPLE 1
  public static void Main()
     {
             StudentName student1 = new StudentName("Marcus", "Deatonus");
 ...
     }
  EXAMPLE 2
  public static void Main()
     {
             StudentName student1 = new StudentName
               {
                      FirstName = "Chris",
          LastName = "Bellcamp"
       };
 ...
      }
REFERENCES 
http://msdn.microsoft.com/en-us/library/vstudio/bb397680.aspx 
 
 
 
          
      
 
  
 
 
 
 
 
 
 
 
 
 
No comments:
Post a Comment