Can a struct be derived from a class in c#?
If not, Why can primitive data types, such as int, be derived from the class object? Since the data type int is basically a struct type(value type).
Is this just an exception to the rule?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Integers and other value types (e.g. bool) are objects, because it allows them to leverage inheritance (i.e. they have access to the common
.Equals(),.GetType(),.ToString()functions).It’s a design decision in the .NET framework. Rather than writing separate functions for all the value types under System.ValueType, they use a common code base.
Microsof’s document on Types