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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:42:38+00:00 2026-06-13T05:42:38+00:00

As everybody knows using virtual keyword for a method in a class allows us

  • 0

As everybody knows using virtual keyword for a method in a class allows us to override it in its derived sub-class. However, method still has to stick to the same signature e.g. return value, argument and etc.

Question: in C#, how can I can override the signature as well? is this possible?

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-13T05:42:39+00:00Added an answer on June 13, 2026 at 5:42 am

    It is not possible. You can create an overload, though, if you need it.

    Edit

    To make my case against new, please consider the case where you have a base object, and one that inherits from it. By placing new before the method of which you’re attempting to “change” the method signature, you’re actually wasting four key strokes.

    public class Base {
        public string Foo () { return null; }
    }
    
    public class Inherited : Base {
        public new int Foo () { return 0; }
    }
    

    Now, Inherited has two methods:

    public string Foo () { return null; }
    public int Foo () { return 0; }
    

    You are not actually changing the method signature. Thus, the new keyword isn’t even needed. You will get the same effect without it:

    public class Inherited : Base {
        public int Foo () { return 0; }
    }
    

    The use of new is to override a non-virtual member of a base class:

    public class Base { 
        public string Foo () { return null; }
    }
    
    public class Inherited : Base {
        public new string Foo () { return "Something else..."; }
    }
    

    But you will run into issues with this if you don’t pay attention to this subtlety. With virtual you get a virtual look-up table that will map your functions to the correct call. With new, you will not. If you pass in Inherited where a Base object is required (this will work, of course), the Base class’s Foo() will be called! Not, the Inherited “override” of Foo().

    This is not the same behavior as overriding a virtual member.

    public static class MyClass {
        public string MyMethod (Base @base) {
            return @base.Foo ();
        }
    }
    
    [Test]
    public void then_it_should_return_non_null () {
        var obj = new Inherited ();
        var result = MyClass.MyMethod(obj);  // obj will get upcasted to Base
        Assert.That (result, Is.EqualTo(obj.Foo ())); // Assert fails!
    }
    
    [Test]
    public void inherited_should_return_correct_value ()
    {
        var obj = new Inherited ();
        var result = obj.Foo ();  // will access the "new" method, hiding Base's implementation
        Assert.That (result, Is.Not.Null);  // Assert passes! 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

everybody using mysql knows: SELECT SQL_CALC_FOUND_ROWS ..... FROM table WHERE ... LIMIT 5, 10;
Everybody knows you're not supposed to compare floats directly, but rather using a tolerance:
Everybody knows that you can access a variable in PHP using this: ${'varName'}. But
Everybody knows that you should close a connection immediately after you finish using it.
As everybody knows the en-US Keyboard-layout is the best one for programming. So I'd
As everybody knows, you have limited precision when you use printf to output the
As almost everybody knows strings in Java are immutable. Recently I discovered something that
I want to implement a class in c++ that has a callback. So I
I'm getting screen coordinates using this: @Override public boolean onTouchEvent(MotionEvent ev) { x =
Hy everybody, I'm trying to implement a neural network with matlab using nntool. Does

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.