Header Files

You don't use them in C#.  C# is more "programmer friendly". When dealing with files of the same project, instead of manually specifying "header file" every time, it will go and look in all the project files for a match according to the namespace.

Read More

Include in C#

C# doesn't use #include All of the classes in all of the files are automatically available everywhere.  If a class is created inside the same project namespace then it can be used everywhere.  If it's in a different namespace you 'include' it with the "using" keyword. There is no replacement for a C++ #include statement in C#. C# is an object-oriented […]

Read More

Using Error Catching

Typical Try Catch Throw You can use throw in a try block to cause execution to jump out to the catch block, or in a class to cause the calling functions error handler to be invoked.

Read More

.Strings General

string or String string is an alias in C# for System.String.So technically there is no difference (it’s like int and System.Int32). Best practice: Use string any time you’re referring to an object. Use String if you need to refer specifically to the class. Multi Line Strings Use the ‘@’ character before the string to create […]

Read More

.Arrays

List or Array? If your going to be resizing your array as you add and remove items often using a list is best (resizing an array causes it to be copied).  If you need to be able to access array elements by index (rather than using for each) then use an array.  If you need […]

Read More

Variables

The structure below shows the various basic types of C# and the types they map to in the .Net framework. C# Short Name .Net Class Declaration Description bool Boolean bool isValid = true; 8 bit true or false sbyte SByte sbyte b = -1 signed 8 bit integer byte Byte byte b = 1; 8 bit […]

Read More

#define

Source code based #define isn’t available in C# like in C++. You can’t use it to create macros. Bloody annoying, but get over it – you can’t!  Instead, use constants. See constants here Example C# define usage #if DEBUG See here. How #define is used in C# #define is only used to create something to […]

Read More

References

Add project references (e.g. .NET, COM etc plug ins) by right clicking References in Solution Explorer

Read More

Platform Target

A classic source of run problems in C# can be if your using components that are 32bit in an application with the Platform.  Setting the Platform Target to x86 will often solve this whilst still allowing the app to run on an x64 platform. Menu > Project > Project Properties > Build > Platform Target

Read More