Skip to content

Instantly share code, notes, and snippets.

@satoyuichi
Last active May 31, 2022 04:57
Show Gist options
  • Save satoyuichi/050558bce0a2f1b1d408992dc3d65938 to your computer and use it in GitHub Desktop.
Save satoyuichi/050558bce0a2f1b1d408992dc3d65938 to your computer and use it in GitHub Desktop.
if 文地獄対策
using System;
using System.Collections.Generic;
delegate bool ConditionCheck ();
class CheckAndAction {
public ConditionCheck check { get; set; };
public Action action { get; set; };
}
caList = new List<CheckAndAction> ();
caList.Add ( new CheckAndAction() {
check = () => {
// 条件を満しているかどうかで true か false を返す
return true;
},
action = () => {
// 上の条件を満していた場合に実行する処理を書く
}
}
);
foreach (CheckAndAction ca in caList)
{
if (ca.check ()) {
ca.action ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment