Extension Methods Flashcards Preview

.NET / C# > Extension Methods > Flashcards

Flashcards in Extension Methods Deck (5)
Loading flashcards...
1

What is an extension method?

Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.

2

How to declare an extension method?

Via a static class with a static method. The method must has a this (only one, even for multiple params) keyword in the beginning.
e.g:
static public double ToDouble(this string data)

3

What is a good place to store extension methods?

In its own namespace... e.g: Model.Employee.Extensions, or Your.Current.Namespace.Extensions

4

Can an extension be called in a regular way (MyStaticClass.DoSomething(param))?

Yes... the static class reamains as is. Actually, the "this" keyword makes the static class an extension.

5

How does visual studio diferentiate normal methods from extension methonds?

extension methods has a transparent box with down arrow.