Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which parts of C# .NET framework are actually parts of the language?

Tags:

c#

I am wondering which parts of the System are language features (core components), and which parts are just useful filler, but aren't strictly necessary. I may be off with the wording here, so let me illustrate with an example what I mean.

Consider System.Console class it's obviously something that is used for something very particular. In essence, this thing is there to play nice with a feature of Windows / current OS. It's not what I would call a core component of the language.

On the other hand, take the System.IDisposable interface. That thing's obviously very important, as without it the using() statement is useless. A class needs to implement this particular interface for a language feature to kick in.

I could assume that the mscorlib is the responsible party here. A quick glance with the Object explorer shows that it indeed houses many of the components I can agree are core, while at the same time it puts the Console class into System namespace, which is just filler.

This notion of placing filler and language-specific objects into the same namespace equates them, but for a deeper understanding of C#, I would like to know which is which. So, I'm looking for a list of core components of C#. I'm assuming that there's a handy reference somewhere, but since I was asleep during the google-lecture I was unable to form the correct query to find it.

Thanks in advance.

Much later EDIT I read this Lippert blog post, it's kind-of-related. Interestingly foreach construct doesn't actually require IEnumerable interface to function.

like image 844
Gleno Avatar asked Jan 29 '11 09:01

Gleno


1 Answers

There aren't very many types actually required by C#. Ones which I can think of off the top of my head and with a quick check of the spec:

  • System.Object
  • System.Enum
  • System.ValueType
  • The primitive types: System.{Int16,Int32,Int64,UInt16,UInt32,UInt64,Byte,SByte,Double,Single,Char,Boolean}
  • System.String
  • System.Decimal
  • System.Nullable<T>
  • System.Array
  • System.Exception (and various subclasses - see section 16.4 of the spec)
  • System.Delegate (and possibly System.MulticastDelegate)
  • System.IDisposable
  • System.Attribute (and some specific attributes, such as ConditionalAttribute and ObsoleteAttribute)
  • System.Type
  • System.Collections.IEnumerable / IEnumerator
  • System.Collections.Generic.IEnumerable<T> / IEnumerator<T>
  • System.Collections.Generic.IList<T>
  • System.Threading.Monitor
  • System.Threading.Interlocked
  • System.Linq.Expressions.Expression<T>
  • Task and Task<T> for C# 5
  • System.GC (mentioned in the spec, but not explicitly used by the compiler AFAIK)

Now any target framework is going to require more types than that for the implementation of course - things like MethodInfo as mentioned in comments, probably attributes to decorate out parameters (and a whole bunch of other types for dynamic typing). But different target systems could have different implementations of that - you couldn't depend on them when writing truly portable C#.

like image 150
Jon Skeet Avatar answered Nov 15 '22 23:11

Jon Skeet