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 1077239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:32:47+00:00 2026-05-16T21:32:47+00:00

I understand delegates as a shortcut for defining a class with one method but

  • 0

I understand delegates as a shortcut for defining a class with one method but what is the meaning of bar2 below? It compiles. But I can’t see what an inner class would do here. I know I’m missing something so that’s why I’m asking (this is not homework, I’m at work-work right now).

namespace ns2 { public delegate void bar();}
public class foo
{
    private ns2.bar _callback;
    public foo(ns2.bar callback) { _callback = callback; }
    public void baz() { _callback(); }
    public delegate void bar2();
}

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-05-16T21:32:48+00:00Added an answer on May 16, 2026 at 9:32 pm

    It’s just declaring a nested type, that’s all. As it’s public, there’s pretty much no difference between that being declared inside the type and being declared outside.

    Other classes will have to refer to it via the name of the containing type (unless they have a using directive specifically for it):

    public class OtherClass
    {
        private void DoSomething()
        {
            foo.bar2 action = delegate { ... };
            foo f = new foo(action);
            ...
        }
    }
    

    Usually when I write a nested type, it’s private – it’s just a helper class for the containing class; an implementation detail. That doesn’t have to be the case, of course, but it should at least be true that the nested type is meaningless unless you’re in some way using the outer class. For example, it could be a builder for the outer class, or an enum used in some parameters for a method call within the outer class.

    (By the way, it’s useful when writing sample code like this to follow .NET naming conventions even for meta-syntactic names like Foo and Bar. It makes the difference between variables and types clearer, for example.)

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

Sidebar

Related Questions

I was just trying to understand delegates using the following code. public class delegatesEx
Whilst learning events and delegates I can't help but think about the Observer design
I understand how delegates and events work. I can also imagine some common scenarios
I understand lambdas and the Func and Action delegates. But expressions stump me. In
What is the Java equivalent of Cocoa delegates? (I understand that I can have
I can easily understand how to use custom events in pure C# code, but
I understand delegates encapsulate method calls. However I'm having a hard time understanding their
im trying to learn delegates and events in c#, i understand that an event
Using a delegate I can call any function asynchronously. From the documentation I understand
I would like to know about the Invoke(delegate) method. I do not understand why

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.