none
Query RRS feed

  • Question

  • How can I write this code as a method?

                var list = AnaTabloBusiness.GetTreeData();
                Func<TblAnaKayit, int, bool> isParent = null;
                isParent = (a, i) => a != null && (a.Id == i || isParent(list.FirstOrDefault(x => x.Id == a.ParentId), i));
    Thanks

    Wednesday, November 15, 2017 8:22 PM

Answers

  • Try this function:

    static bool IsParent(T list, TblAnaKayit a, int i)
    {
       return a != null && (a.Id == i || IsParent(list, list.FirstOrDefault(x => x.Id == a.ParentId), i));
    }

    Replace T with the type of your list. (Maybe it is List<TblAnaKayit>).

    • Proposed as answer by Fei HuModerator Thursday, November 16, 2017 1:25 AM
    • Marked as answer by Kenan YILMAZ Sunday, December 10, 2017 6:52 PM
    Wednesday, November 15, 2017 8:39 PM

All replies

  • Try this function:

    static bool IsParent(T list, TblAnaKayit a, int i)
    {
       return a != null && (a.Id == i || IsParent(list, list.FirstOrDefault(x => x.Id == a.ParentId), i));
    }

    Replace T with the type of your list. (Maybe it is List<TblAnaKayit>).

    • Proposed as answer by Fei HuModerator Thursday, November 16, 2017 1:25 AM
    • Marked as answer by Kenan YILMAZ Sunday, December 10, 2017 6:52 PM
    Wednesday, November 15, 2017 8:39 PM
  • Hello Kenan,

    Do you have anything to update?  If you already have got the useful solution from there, you could close the thread by marking the useful reply  as answer, This can be beneficial to other community members reading this thread. Thanks a lot.

    Sincerely,
    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Marked as answer by Kenan YILMAZ Sunday, December 10, 2017 6:52 PM
    • Unmarked as answer by Kenan YILMAZ Sunday, December 10, 2017 6:52 PM
    • Edited by Fei HuModerator Monday, December 11, 2017 1:09 AM
    Sunday, November 26, 2017 11:47 AM
    Moderator