How do I extend a class with c# extension methods?
问题 Can extension methods be applied to the class? For example, extend DateTime to include a Tomorrow() method that could be invoked like: DateTime.Tomorrow(); I know I can use static DateTime Tomorrow(this Datetime value) { //... } Or public static MyClass { public static Tomorrow() { //... } } for a similar result, but how can I extend DateTime so that I could invoke DateTime.Tomorrow? 回答1: You cannot add methods to an existing type unless the existing type is marked as partial, you can only