Tuesday 15 March 2011

c# - How can I write a "fluent" datetime value? -


How do I write the C # code that will allow the following code to be compiled:

  Var date = 8th September (2013); // Generate date time for date 8 of September 2013    

You can specify an extension The method can be used:

  Public static class MyExtensions {public static dateTime September (this int day, int year) {new date time (year, 9, day); However, this is generally bad behavior, and I recommend against this kind of thing, especially for something as trivial - like this  new date time (2013, 9, 8) < / Code> Really much more than  8. September (2013) ? There may be times where such trick can be useful or fun to practice, but it should be used at least.   

No comments:

Post a Comment