Teague Teague - 2 months ago 8x
C# Question

Why is the #include directive not necessary in C#?

Why is the #include directive not necessary in C#? Is this due to the fact that C# has a more developed/inclusive/restrictive compilation process vs the raw nature of C/C++ preprocessor, compiler, linker, etc.? (i.e. you're developing in Visual Studio for C#).

I'm just curious how the compilation process knows where to look for additional classes.

Edit: I realize you wouldn't need the actual #include statement in C# because that doesn't make sense. However, I'm more curious as to how your C# program is aware of the existence of other classes without any kind of indicator.


C# has something similar. To use classes in other libraries etc. you need to add a reference to the assembly and then use the using key word followed by the name of the reference like this:

using System.Collections.Generic

This example namespace would enable me to access classes such as Dictionary<TKey, TValue> etc.

For more info on references see here.