Consider the following method example:
public static string[] ParseOptions()
{
return Environment.GetCommandLineArgs();
}
What would I have to do to create an extension that would make ParseOptions() return all command line arguments in lower case?
I would like to be able to use the extension as follows:
var argArray = ParseOptions().MyExtToLower();
Note: I’m asking this to better understand how to create an extension for a method. I’m not actually interested in getting lower case command line arguments this way.
Notice the
thiskeyword in the parameter list. That is what makes it possible to call the method like this:To be clear, you’re not actually adding an extension to a method here. What you are doing is adding an extension to the type that the method returns.