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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:21:32+00:00 2026-06-12T09:21:32+00:00

I have a 2 classes one is base class and second is derived class.

  • 0

I have a 2 classes one is base class and second is derived class.
Want to restrict object slicing, how can I do it using C#.net ?

  • 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-12T09:21:32+00:00Added an answer on June 12, 2026 at 9:21 am

    UPDATE:

    My initial thoughts as described below were found as not true:
    See: C++ slicing in Java / C#


    Original Answer:

    If I understood correctly this is a theoretical question.
    REDUCING slicing can be done by not defining new members in the derived class.

    slicing occurs when assigning an instance of a derived class to a base class reference type.
    In this case the system does not know where to allocate a new data-type because it is defined in the derived class only and not in the base class.

    But there is no way to RESTRICT that, this is what suppose to happen and it is defined as

    A natural and unavoidable consequence of assignment by value from
    subclass objects

    Object slicing – Wikipedia

    however you can declare a class as sealed to prevent inheritance that will restrict object slicing because it will prevent the cause (Inheritance) so you will not have a derived class to assign to a base reference by value.

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

Sidebar

Related Questions

I have two classes: one base class an one derived class The base class
I have two classes - one base class and one derived from it :
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes, one that inherits from the other. The base class is
I am using Hibernate to do mapping. One of my classes have a set
First I want to describe my situation briefly. I have two classes, one MainClass
I have two app. The one use XAF (devexpress framework), the second use asp.net
I have a virtual base class and two classes that implement the various methods.
One challenge using hibernate is that manged classes have to have a default constructor
So say, for example I have two classes: Base = declarative_base() class Vendor(Base): __tablename__

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.