This List <string> ListName as parameter?

What does it mean when you have this list as a method parameter?

public static void KillZombies(this List<Zombie> ZombiesToKill, int NumberOfBullets)
{
    ...
}
+3
source share
2 answers

This would mean that the Method Extension Method :

The code calling the method may look a bit confusing:

var zombies = new List<Zombie>();
zombies.KillZombies(15);

In fact, it is a kind of syntactic sugar that is equivalent to:

public static void KillZombies(List<Zombie> zombiesToKill,
                               int numberOfBullets)
{
    // Code here
}

With calling code similar to:

var zombies = new List<Zombie>();
KillZombies(zombies, 15);
+8
source

This is an extension method .

In this case, the extension List<Zombie>. You would call it this way:

listOfZombies.KillZombies(numberOfBullets);

If the type listOfZombiesis equal List<Zombie>, a numberOfBulletsis an integer.

+1
source

Source: https://habr.com/ru/post/1775277/


All Articles