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

  • Home
  • SEARCH
  • 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 8154163
In Process

The Archive Base Latest Questions

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

I am a Java programmer trying to transition to C# and I’m hoping there’s

  • 0

I am a Java programmer trying to transition to C# and I’m hoping there’s a way to do something in C# that I’m accustomed to in Java: overriding a method in the declaration of an abstract object like so:

//This is the way I do it in Java and want to do in C#
Keyword k = new Keyword("quit"){
    public abstract void do(String context){
        //TODO Do stuff
    }
};

This is for some text game stuff I’ve been doing for a while in Java. I’ve looked into abstract and virtual and anonymous classes but none of them do exactly this. Abstract and virtual want me to create a whole new subclass, but this would be time consuming and unfeasible on a large scale. Anonymous classes don’t (as far as I can tell) enable me to override methods, just fields and don’t provide any stabilization for me to rely on.

If there is a way to do this or something similar please explain. Thanks for your time.

  • 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-06T16:15:02+00:00Added an answer on June 6, 2026 at 4:15 pm

    That doesn’t work in C#. You’ll have to create a new class that inherits from Keyword.

    public class MyKeyword : Keyword
    {
        public MyKeyword(string s) : base(s)
        { }
    
        public override void do(string context)
        {
            // TODO: Do stuff.
        }
    }
    

    Anonymous Types in C# aren’t classes that you can provide any public methods for. They only have properties, and are intended to be a quick, intra-method way of pasing complex data from one line to the next.

    To be honest, I didn’t know you could do what you show in Java. That is, if I’m understanding it as kind of an in-line class derivation.

    Brian Rasmussen mentions using a delegate. That would look something like this:

    public delegate void DoSomething(string context);
    public class Keyword
    {
        public DoSomething Do;
    
        private void CallsDo()
        {
            if (Do != null)  Do("some string");
        }
    }
    

    Then you can assign to it:

    Keyword k = new Keyword();
    k.Do = (ctx) => { /* Do something with ctx string */ };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a C/C++/Java programmer working with JavaScript. I'm trying to write a function that
I am a Java programmer who learns Haskell. I've written a small program that
I am a java programmer, I found that Java is very good at doing
I am not an experienced Java programmer and i'm trying to write some text
Trying to get a feel for haskell. Am a seasoned programmer with PHP, JAVA,
I have been a Java programmer for a while and I am trying to
I'm not the worlds most experienced Java programmer, and I'm trying to create a
I'm trying to create a java desktop application that holds desktop icons. The app
I am a very novie Java programmer.I am trying to sort an array of
I'm an experienced C++/.NET/Java Windows/web programmer trying to learn (Common) Lisp. I'm reading Practical

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.