1

The datatype int refers to System.Int32, which is a structure. I had few basic questions.

  1. How does it become a value type instead of a reference type.
  2. The structure is inheriting other interfaces and has methods implemented.

Can a structure inherit and can it hold implementation methods of the interfaces.

6

3 Answers 3

4

How does it become a value type instead of a reference type.

It becomes a value type as all other types in .NET do, by being declared as a struct, and not a class.

Can a structure inherit and can it hold implementation methods of the interfaces.

A struct cannot inherit, but can implement interfaces. int32 is a value type. Why cant they inherit? More on that in Why don't structs support inheritance?

By viewing the source, you can easily see that Int32 implements a bunch of interfaces:

public struct Int32 : IComparable, IFormattable, IConvertible, IComparable<Int32>, IEquatable<Int32> 
Sign up to request clarification or add additional context in comments.

Comments

2
  1. int and Int32 are the same thing, they are both value types int doesn't become a reference type.

  2. Stucts can implement interfaces

Comments

2

As to your question int is just an alias that points to Int32 struct. The structure is some sort of lightweight object that is stored on stack whilst normal objects (classes) are stored on heap. Struct cannot inherit classes but only interfaces. It's also not possible to inherit from it. You can find a lot of information about structs here on StackOverflow or if you google for it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.