clr - C# System.Object being the ultimate base class -


in msdn spec, notice system.object ultimate base class in .net. system.valuetype abstract class inheriting system.object , overrides methods equals, compare etc... value types bool, int etc.. inherit system.valuetype other .net objects inherits system.object.

i have 2 questions on this.

  1. what need of system.object? why wasn't interface preferred on here?

am assuming has 2 direct children(ignoring can create more) system.valuetype , system.referencetype both having entirely different implementations.

**edit:**there no system.referencetype. there sytem.object , sytem.valuetype (overriding base class). apologies here.

system.object may needed handle basic clr functionalities object creation using new(), enforcing default constructor, gc etc ?

  1. when de-compile sytem dll, , see implementation of bool, see struct.
    class (say exception) don't see inheritance system.referencetype or system.object. how inheritance handled ?
    infact, common type system doing mycustomclass make inherit system.object(since inheritance determined @ compile time thinking cts doing it)

please feel free correct me/edit post if understanding wrong.

enter image description here

you have many questions in question. in future, consider posting 1 question per question.

what need of system.object?

the question vague. let me rephrase.

why c# type system designed non-pointer types had common base type?

to gain benefits of polymorphism. in type system has no generics, c# 1.0 type system, want able make list of arbitrary objects.

why wasn't interface preferred on class type?

interfaces specify capabilities. base classes allow shared implementation. methods on object have implementations shared amongst derived types.

am assuming has 2 direct children(ignoring can create more) system.valuetype , system.referencetype both having entirely different implementations.

this totally false.

so system.object may needed handle basic clr functionalities object creation using new()

no.

enforcing default constructor

no. though true default constructor of object called, constructor doesn't anything. saying purpose of type ensure constructor doesn't called strange thing say.

gc etc ?

no.

when de-compile system.dll, , see implementation of bool, see struct.

correct. expected know non-nullable, non-enum structs inherit directly system.valuetype.

for class (say exception) don't see inheritance system.referencetype or system.object.

correct. expected know class types inherit system.object (if no other type specified, of course.)

how inheritance handled ?

the question vague answer.

what common type system doing mycustomclass make inherit system.object(since inheritance determined @ compile time thinking cts doing it)

i have absolutely no idea you're trying ask here. try making question more precise.

a question did not ask should have asked is:

what mean when type inherits type b?

it means members of type b members of type a.

all members? private members?

yes. inheritance property members of 1 type members of another.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -