-3

Similar to Object being the ultimate base class, what is the root or base interface applied to all primitive types in c#?

I am suspecting it to be iConvertible

N_E
  • 743
  • 10
  • 16
  • just a search away: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/built-in-types .... – Octavian Mărculescu Aug 10 '22 at 20:10
  • 1
    Primitive types are not classes, they are structs (value types, not reference types), hence they don't have any base class. Sure, they implement some interfaces, but no base class. – Octavian Mărculescu Aug 10 '22 at 20:12
  • 1
    Does this answer your question? [Can I define a method that only accepts primitive types?](https://stackoverflow.com/questions/24169901/can-i-define-a-method-that-only-accepts-primitive-types) – Progman Aug 10 '22 at 20:12
  • Is it an option to use `ValueType`? – Progman Aug 10 '22 at 20:14
  • Purely trolling note: C# does not have "primitive types", there are some types in .Net that are marked as "IsPrimitive" and most happen to map to C# built in types... – Alexei Levenkov Aug 10 '22 at 20:16

1 Answers1

1

If you are referring to the built-in types like int, long, string etc. then there isn't a single base class that is common to them all.

Types like int, long, float all inherit from System.ValueType, but not all built-in types are value types - string for example is a reference type and as such, does not inherit from System.ValueType but from System.Object.

You can find the full list of C# type keywords to their .NET class counterparts here

Be aware that IConvertible is not a base class - it is an interface. You don't inherit from an interface, you implement it - in other words, an interface is merely a contract that a class needs to adhere to if it chooses to implement it.

If you look at the docs for the built-in types you'll find they all implement a range of interfaces, of which IConvertible is one of them but it's not the base class of those types as mentioned above.

lee-m
  • 2,269
  • 17
  • 29