Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:34:15+00:00 2026-06-14T16:34:15+00:00

I am working on implementing a graph class. In class I learned that the

  • 0

I am working on implementing a graph class. In class I learned that the breadth-first and depth-first traversals are the same algorithms except to store the traversing nodes a queue and stack is used respectively. So I put all my logic into a Traversal() method which is called by DepthFirstSearch() which passes in a stack as the ADT.

public void DepthFirstSearch(GraphNode<T> root)
{
    Stack<GraphNode<T>> s = new Stack<GraphNode<T>>();

    Action<GraphNode<T>> insert = s.Push;
    Func<GraphNode<T>> retrieve = s.Pop;
    //Func<int> stackCount = s.Count; Cannot implicitly convert type 'int' to System.Func<int>' error
    Func<int> stackCount = () => s.Count;

    Traversal(root, insert, retrieve, stackCount);
}

I am assuming that I cannot pass s.Count into a delegate because it is a class property? So to get around it I used a lambda to closure around that property. But can anyone explain why I need lambda for s.Count but not for s.Pop or s.Push? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:34:18+00:00Added an answer on June 14, 2026 at 4:34 pm

    The reason is because Stack<T>.Push and Stack<T>.Pop are already functions that are compatible with the type of delegate (Func<TResult> and Action<T>, where TResult and T match the generic type parameter of your Stack<T>—in your case, GraphNode<T>) to which you’re trying to assign the methods. If they weren’t compatible, you would need to use a lambda function or some other sort of wrapper delegate to assign the method to your delegate variable.

    While a class property technically consists of a getter and a setter method, in C#, those details are abstracted away, requiring you to wrap a class property in a lambda function. Also, per Servy’s comments below, the compiler wouldn’t be able to easily determine whether you’re trying to assign the getter or the setter to the delegate variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a property panel for a graph editor that I'm working on in
I'm working on implementing a single pass depth-peeling algorithm by using atomic textures in
I'm working on implementing a way to allow HTML in a field that I
I am currently working on implementing the constructor function for the vector class(my professor
I'm working on implementing omniauth into a Rails project. My problem is that the
Short story, I'm implementing a graph and now I'm working on the Kruskal, I
I am working on implementing Zend Framework within an existing project that has a
I am working on implementing use of the mysql class found here in an
I am working on implementing a function that would execute another function a few
I am working on implementing tabs for my application. Everything is working well except

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.