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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:55:03+00:00 2026-06-08T02:55:03+00:00

C# allows you to define an implicit cast to a delegate type: class myclass

  • 0

C# allows you to define an implicit cast to a delegate type:

class myclass
{
    public static implicit operator Func<String, int>(myclass x)
    {
        return s => 5;
    }
    public static implicit operator myclass(Func<String, int> f)
    {
        return new myclass();
    }
}

But unfortunately, we can’t use this to make an object look like a function:

var xx = new myclass();
int j = xx("foo");    // error
Action<Func<String, int>> foo = arg => { };
foo(xx);              // ok

Is there a nice way to make an object of one’s own class accept function-style parameters (arguments) directly on of its base instance? Kind of like an indexer, but with parentheses instead of square brackets?

  • 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-08T02:55:05+00:00Added an answer on June 8, 2026 at 2:55 am

    No, C# does not allow that as part of the language. Underneath the covers, the CLI uses the call and callvirt instructions to invoke a method or, indirectly, a delegate.

    So, unlike Python where you can make an instance of a class callable by declaring a def __call__ method, C# has no similar feature.

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

Sidebar

Related Questions

Eclipse allows us to define a class as: interface MyInterface { void methodA(); int
Say I have a class, something like the following; class MyClass { public: MyClass();
I have a generic class that I'm trying to implement implicit type casting for.
I'd like to define an generic interface that allows nullable value types (int?, double?,
I am trying to have a class that allows implicit casting to certain built
Is there any mechanism in C# that allows one to define and declare an
Currently the HashSet<T> constructor that allows you to define your equality comparison yourself is
An app allows a user to define an arbitrary set of days like so:
I want to define a class that supports __getitem__ , but does not allow
There is a @Bean annotation in Spring 3.0. It allows to define a Spring

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.