C# is a modern, object-oriented programming language developed by Microsoft. It was first introduced in 2000 as part of the .NET framework and has since become one of the most popular programming languages in the world. C# is designed to be simple, powerful, and easy to learn, making it an ideal choice for both beginners and experienced programmers. This cheat sheet lists just the “get started”-syntax. Enjoy!
Cheat Sheet
Syntax | Description |
---|---|
using | Used to include namespaces in the program |
namespace | Used to define a namespace |
class | Used to define a class |
struct | Used to define a structure |
interface | Used to define an interface |
enum | Used to define an enumeration |
delegate | Used to define a delegate |
public | Access modifier that allows access from any code in the program |
private | Access modifier that allows access only within the same class |
protected | Access modifier that allows access within the same class and derived classes |
internal | Access modifier that allows access within the same assembly |
static | Used to define a static member that belongs to the class rather than an instance of the class |
readonly | Used to define a read-only field that can only be set in the constructor |
const | Used to define a constant value that cannot be changed |
virtual | Used to define a method that can be overridden in a derived class |
override | Used to override a virtual method in a derived class |
abstract | Used to define an abstract class or method that must be implemented in a derived class |
sealed | Used to prevent a class from being inherited |
new | Used to hide a member of a base class in a derived class |
base | Used to access members of a base class from a derived class |
this | Used to refer to the current instance of a class |
try-catch | Used to handle exceptions in the program |
finally | Used to execute code after a try-catch block, regardless of whether an exception was thrown |
throw | Used to throw an exception |
using | Used to automatically dispose of resources when they are no longer needed |
var | Used to declare a variable with an inferred type |
foreach | Used to iterate over a collection of items |
if-else | Used to conditionally execute code |
switch | Used to conditionally execute code based on the value of a variable |
while | Used to execute code repeatedly while a condition is true |
do-while | Used to execute code repeatedly until a condition is true |
for | Used to execute code repeatedly for a specified number of iterations |
continue | Used to skip to the next iteration of a loop |
break | Used to exit a loop |
return | Used to return a value from a method |
out | Used to pass a parameter by reference |
ref | Used to pass a parameter by reference |
params | Used to pass a variable number of arguments to a method |
yield | Used to return a sequence of values from a method |
Reference: C# documentation