Can you use an extension method on a type instead of an instance of the type?
I can have an extension method like this:
DateTime d = new DateTime(); d = d.GetRandomDate();
GetRandomDate is my extension method. However, the above doesn't make a lot of sense. Which would be better:
DateTime d = DateTime.GetRandomDate();
However, I don't know how to do this. Extension method created as:
public static DateTime GetRandomDate(this System.DateTime dt)
will only add GetRandomDate () to the first example above, not the second. Is there a way to achieve the desired behavior?
+2
a source to share
3 answers