Declaring classes in C#

The syntax for declaring classes is a major point of departure between C# and C++. With C#, the entire definition of a class lives in a single file. In C++, you would typically have both a header file that contains a declaration of the class (and may optionally contain the inline declaration of some of the simpler methods) and an implementation file usually with the extension .c or .cpp that contains the bulk of the implementation of the class. You typically distribute the header file to users of your class along with a compiled “.dll” or “.lib” file. The header file functions as a sort of metadata for the classes in the “.dll” or “.lib” file. The following program shows how you would declare and use a class in C#:

 namespace ...

Get .NET and COM Interoperability Handbook, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.