c# - What Advantages of Extension Methods have you found? -


One of the "non-beliefs" of C # was asking me what was the purpose of the extension methods "

I explained that You can add new ways to those items that were already defined, especially when you do not own / control the original item.

He said, "Do not just add one method to your own class?" We are going round and round (in a good way) My general response is that this is another tool in toolbelt , And his reaction is that it is a waste of equipment ... but I thought I would get a more "illuminated" answer.

What are some scenarios that you have used expansion methods that you have not used (or should not) have been added to your class?

I think the extension writing code gets a great deal of help, if you have basic types of extension methods If you add them you will get them in intellisense quickly.

I have to write to use it for a provider provider:

  console.lightline (string.format (new file format format provider), "{0 : Fs} ", filesystems));  

To create an extension method I can write:

  console WrightLine (fileSize.ToFileSize ());  

Cleaner and simple.


Comments