What’s Inside
What is C#?
C# is a general-purpose, object-oriented, high level programming language. The C# programs may contain one or several files with .cs extension. These files are compiled by C# compiler (csc) to executable code as a result assembly is created.
C# development Stack
- Microsoft .NET
- C# specific tools like compiler , linker etc.
- IDE (I am using rider)
First C# Program
1
2
3
4
5
6
7
8
9
10
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("C# is awesome?");
}
}
}
Breaking Everything Apart
Console.WriteLine(“C# is awesome?”);
WriteLine is a static method defined in class called Console.
static void Main(string[] args)
C# cannot execute without entry point. Main method is place where our program begins automatically.
class Program
Like other methods, Main method also cannot stand on it’s own, that’s why it is wrapped with class Program
.
namespace ConsoleApp1
Namespaces exist in C# to avoid name clashes in large projects with many classes. So, classes are wrapped within namespace. It is considered bad to have class without a namespace. And for the classes without namespaces, C# assigns anonymous namespace.