When you use the
sealed
keyword on a class, it prevents any class being derived from it; you can't do this:
public sealed class A {}
public class B : A {}
It doesn't prevent extension methods being declared because they do not
derive from the class, but
extend it.
Extension methods do not get any additional access to the class internals, they just allow a syntactic sugar so you can add methods that look like part of the original class. For example, the DateTime class does not have a method to return the first of the month, so you can do this:
DateTime firstOfMonth;
DateTime now = DateTime.Now;
firstOfMonth = (now.AddDays(1 - now.Day)).AtMidnght();
Or include one:
public static DateTime FirstOfMonth(this DateTime dt)
{
return (dt.AddDays(1 - dt.Day)).AtMidnight();
}
Now your code can use the clearer format:
DateTime firstOfMonth = DateTime.Now.FirstOfMonth();