C#: How to change every object in an Enumerable with one function.

I’m trying to make a short cooldown effect every spell whenever any of the spells is cast. SpellDefinition is the type and AllSpells is the name of the Enumerable, the code for “FindByName” works fine and correctly returns the correct data from the enum when called by name, which I’m using to affect each spell with an individual cooldown. I’ve tried several syntaxes to return all spells, including .take, a foreach loop with and without a get, and a few others, none of which I can get to work. Below is the full code I’m using, including the non-functional FindAll function, as well as the code used to generate the cooldown in another script. How can I write a function to return all of the data in the enum (ideally with a criteria, i.e return all entries with a cost of 5), and then apply that to the showCooldown() function?

public class SpellDefinition
{

	#region Public fields 

	public string Name;
	public string Type;
	public int Cost;
	public string Icon;
	public float Recharge;
	public string Delay;
	public string Description;

	#endregion

	#region Static members

	public static SpellDefinition[] AllSpells = new SpellDefinition[]
	{

		new SpellDefinition { Name = "Festering Strike", Icon = "FeS", Cost = 0, Delay = "Y", Recharge = 0, Type = "Frost/Blood", Description = "An instant attack that deals 200% weapon damage plus 540 and increases the duration of your Blood Plague, Frost Fever, and Chains of Ice effects on the target by up to 6 sec." },
		new SpellDefinition { Name = "Death Coil", Icon = "DC", Cost = 32, Delay = "Y", Recharge = 0, Type = "Runic", Description = "Fire a blast of unholy energy, causing [(1133 + 0.514 * Attack power) * 1] Shadow damage to an enemy target or healing [(1133 + 0.514 * Attack power) * 3.5] damage on a friendly Undead target." },
		new SpellDefinition { Name = "Greater Flare", Icon = "spell-1", Cost = 15, Delay = "Y", Recharge = 4f, Type = "Fire", Description = "Blast of fire deals [color #00FF00]25[/color] damage to target" },
		new SpellDefinition { Name = "Scourge Strike", Icon = "SS", Cost = 0, Delay = "Y", Recharge = 0, Type = "Unholy", Description = "An unholy strike that deals 135% of weapon damage as Physical damage plus 597.  In addition, for each of your diseases on your target, you deal an additional 25% of the Physical damage done as Shadow damage." },
		new SpellDefinition { Name = "Aura of Attunement", Icon = "spell-9", Cost = 25, Delay = "Y", Recharge = 10f, Type = "Spirit", Description = "Your next 2 spells are [color #00ff00]15%[/color] more effective" },
		new SpellDefinition { Name = "Enhanced Strike", Icon = "spell-3", Cost = 5, Delay = "Y", Recharge = 6f, Type = "Spirit", Description = "Attacks with a bladed weapon deal [color #00ff00]15%[/color] more damage for [color #00FF00]5[/color] seconds" },
		new SpellDefinition { Name = "Flame Blade", Icon = "spell-7", Cost = 15, Delay = "Y", Recharge = 20f, Type = "Fire", Description = "Attacks with a bladed weapon deal [color #ff0000]+5 Fire Damage[/color] for [color #00FF00]5[/color] seconds" },
		new SpellDefinition { Name = "Chilling Wind", Icon = "spell-6", Cost = 15, Delay = "Y", Recharge = 10f, Type = "Air", Description = "Attacks dealing fire damage against you and all adjacent party members are reduced by [color #00FF00]10%[/color] for [color #00FF00]2[/color] seconds" },
	};

	internal static SpellDefinition FindByName( string Name )
	{
		return AllSpells.FirstOrDefault( spell => spell.Name == Name );
	}
	internal static SpellDefinition FindAll( string Delay )
	{
		foreach (SpellDefinition spell in AllSpells)
		{
			Get 
			{
			return spell;
			}
		}
	}

	
	#endregion
}

private IEnumerator showCooldown()
	{

		isSpellActive = true;

		var assignedSpell = SpellDefinition.FindByName( this.Spell );

		var sprite = GetComponent<dfControl>().Find( "CoolDown" ) as dfSprite;
		sprite.IsVisible = true;

		var startTime = Time.realtimeSinceStartup;
		var endTime = startTime + assignedSpell.Recharge;

		while( Time.realtimeSinceStartup < endTime )
		{

			var elapsed = Time.realtimeSinceStartup - startTime;
			var lerp = 1f - elapsed / assignedSpell.Recharge;

			sprite.FillAmount = lerp;

			yield return null;

		}

		sprite.FillAmount = 1f;
		sprite.IsVisible = false;

		isSpellActive = false;
		
	}

I’m not aware of a built-in function that does it for arrays, but List got a nice little function called FindAll(Predicate predicate);

If, let’s say your spellDefinitions, instead of an array, was declared like this :

List<SpellDefinition> spellDefinitions = new List<SpellDefinition>();

then, you could do something like

List<SpellDefinition> matches = spellDefinitions.FindAll ( x => x.cost == 5 );

The above line would return all of the spellDefinitions, contained within your list, that have a cost of 5.

If you absolutely need to keep it as an array, I would suggest to add this extensions method in a file called IEnumerableExtensions.cs

using System.Collections;
using System.Collections.Generic;

public static class IEnumerableExtensions {

	public static IEnumerable<T> FindAll<T>(this IEnumerable<T> self, System.Predicate<T> match) {
		List<T> result = new List<T>();
		foreach(T t in self) {
			if(match(t)) {
				result.Add(t);
			}
		}
	}
}

p.s. I wrote this extension method from the top of my head. It is not tested, but the main purpose id there.

If you want to learn more about extensions methods look at this MSDN article