Data Annotation

C# provides data Annotation features. For example, a date needs to be stored in the dd/mm/yy in database & while displaying it in the format dd/mm/yyyy with some built in functions and without any manual conversion.

Here is the Model defined that you can use in your project:
  1.  public class Example  
  2. {  
  3. string _date = "50612";  
  4. public string date  
  5. {  
  6. get  
  7. {  
  8.   
  9. DateTime dt = DateTime.ParseExact(this._date, "ddMMyy", System.Globalization.CultureInfo.InvariantCulture);  
  10. return dt.ToString("dd MMM yyyy");  
  11. }  
  12. set  
  13. {  
  14. DateTime dt = DateTime.ParseExact(value, "dd MMM yyyy", System.Globalization.CultureInfo.InvariantCulture);  
  15. this._date = dt.ToString("ddMMyy");  
  16. }  
  17. }  

Ebook Download
View all
Learn
View all