Last active
August 29, 2015 13:57
-
-
Save bhargavrpatel/9562545 to your computer and use it in GitHub Desktop.
Something that would go inside your Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CASE I: OBJECTS */ | |
// BEFORE | |
public ViewResult CreateProduct() { | |
// create a new Product object | |
Product myProduct = new Product(); | |
// set the property values | |
myProduct.ProductID = 100; | |
myProduct.Name = "Kayak"; | |
myProduct.Description = "A boat for one person"; | |
myProduct.Price = 275M; | |
myProduct.Category = "Watersports"; | |
} | |
// AFTER (Using Initializers in C#) | |
Product myProduct = new Product { | |
ProductID = 100, Name = "Kayak", Description = "A boat for one person", Price = 275M, Category = "Watersports" | |
}; | |
/* CASE II: COLLECTIONS */ | |
// AFTER (Using Initializers in C#) | |
public ViewResult CreateCollection() { | |
string[] stringArray = { "apple", "orange", "plum" }; | |
List<int> intList = new List<int> { 10, 20, 30, 40 }; | |
Dictionary<string, int> myDict = new Dictionary<string, int> {{ "apple", 10 }, { "orange", 20 }, { "plum", 30 }}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment