public static int[] GetSelfAndChildrenIds(int id) { if (LevelPath.TryGetValue(id, out var result)) { return(result); } else { var dept = Get(id); if (dept == null) { return(new int[] { }); } result = CalcSelfAndChildrenIds(id); LevelPath.Add(id, result); return(result); } }