Skip to content

Instantly share code, notes, and snippets.

@bhargavrpatel
Last active August 29, 2015 13:57
Show Gist options
  • Save bhargavrpatel/9562495 to your computer and use it in GitHub Desktop.
Save bhargavrpatel/9562495 to your computer and use it in GitHub Desktop.
Simplifying C# properties
namespace LanguageFeatures.Models {
public class Product {
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public string Category { set; get; }
}
}
// Getter and setter etc have to be set manually like this.
namespace LanguageFeatures.Models {
public class Product {
private int productID;
private string name;
private string description;
private decimal price;
private string category;
public int ProductID {
get { return productID; }
set { productID = value; }
}
public string Name {
get { return name; }
set { name = value; }
}
public string Description {
get { return description; }
set { description = value; }
}
//...and so on...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment