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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:37:35+00:00 2026-05-19T00:37:35+00:00

Here is an easy question (C# noob here) and I can’t find how to

  • 0

Here is an easy question (C# noob here) and I can’t find how to do this (I have C# 4.0 reference from Schildt but not sure what I am looking for yet).

Say I have two objects created by two different classes, but have fields and/or methods with the same name. For example:

public class Object1 {
  bool enable;
  public void Reset(){
    enable = false;
  }
}

public class Object2 {
  bool enable;
  public void Reset(){
    enable = false;
  }
}

Objects are very dissimilar, justifying the creation of two different objects. However, I have many objects with the common ‘enable’ field and ‘Reset()’ method.

So here is what I would like to do (in pseudocode or whatever this is):

void Manipulate(ref object pObj){
  (pObj).enable = true;
  (pObj).Reset();
}

void Main(){
  Manipulate(obj1);
  Manipulate(obj2);
}

How can I do this? I am not sure how to create an object that can point to objects from different classes.

Thanks!


Thanks to all the answers. I went through interfaces and understood them as an ‘alias’ and couldn’t figure out what was the usefulness of them.

  • 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-19T00:37:36+00:00Added an answer on May 19, 2026 at 12:37 am

    This is what interfaces are for:

    public interface ICanResetAndEnable
    {
        // Note: interfaces cannot have fields, only properties and methods.
        bool Enable { get; set; }
        void Reset();
    }
    
    public class Object1 : ICanResetAndEnable {
      bool Enable { get; set; }
      public void Reset(){
        Enable = false;
      }
    }
    
    public class Object2 : ICanResetAndEnable {
      bool Enable { get; set; }
      public void Reset(){
        Enable = false;
      }
    }
    

    You then define your Manipulate method to accept a parameter of any type that implements this interface:

    void Manipulate(ICanResetAndEnable obj)
    {
        // Do whatever.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sure this is any easy question, but I can't figure out what
This must be an easy question but I can't find a properly answer to
Here's an easy one straight from the text book I can't seem to find.
This is most likely not an easy one but here is the situation: I
This is a really easy question I'm sure but I'd appreciate the help. :)
Ok, this is a very easy question for which I could not find the
This should be a really easy derp question, but here it is: I'm trying
So this is probably a fairly easy question to answer but here goes anyway.
Short and easy question, but I seem to have a writer's block here: Suppose
This seems to be an easy question to ask, but I am not able

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.