Fundamentals of C# for beginners
Tags: net, csharp, beginners, programming
Published: 2024-04-03 22:10:53

C# (pronounced "See Sharp") is a modern, object-oriented, component-oriented programming language developed by Microsoft as part of its .NET initiative in the early 2000s. C# provides language constructs to directly support these concepts, making C# a natural language in which to create and use software components. Since its origin, C# has added features to support new workloads and emerging software design practices. 

## **Why Choose C#:**
**Popularity:** C# is one of the most popular programming languages globally.
**Ease of Learning:** It’s straightforward to learn and use, making it an excellent choice for beginners.
**Community Support:** C# has a large and active community.
**Object-Oriented:** C# follows principles like encapsulation, inheritance, and polymorphism.
**Versatility:** It’s used for various purposes, including mobile apps, desktop applications, web services, games, and more.

At its core, C# is an object-oriented language. You define types and their behavior.
Several C# features help create robust and durable applications. Garbage collection automatically reclaims memory occupied by unreachable unused objects. Nullable types guard against variables that don't refer to allocated objects. Exception handling provides a structured and extensible approach to error detection and recovery. Lambda expressions support functional programming techniques. Language Integrated Query (LINQ) syntax creates a common pattern for working with data from any source. Language support for asynchronous operations provides syntax for building distributed systems. C# has a unified type system. 
All C# types, including primitive types such as int and double, inherit from a single root object type. All types share a set of common operations. Values of any type can be stored, transported, and operated upon in a consistent manner. Furthermore, C# supports both user-defined reference types and value types. C# allows dynamic allocation of objects and in-line storage of lightweight structures. C# supports generic methods and types, which provide increased type safety and performance. C# provides iterators, which enable implementers of collection classes to define custom behaviors for client code.

C# emphasizes versioning to ensure programs and libraries can evolve over time in a compatible manner. Aspects of C#'s design that were directly influenced by versioning considerations include the separate virtual and override modifiers, the rules for method overload resolution, and support for explicit interface member declarations.

C# programs run on .NET, a virtual execution system called the common language runtime (CLR) and a set of class libraries. The CLR is the implementation by Microsoft of the common language infrastructure (CLI), an international standard. The CLI is the basis for creating execution and development environments in which languages and libraries work together seamlessly.
 
<u>**WRITING YOUR FIRST C# CODE**</u>
**Hello world**
The "Hello, World" program is traditionally used to introduce a programming language. Here it is in C#:

using System;
namespace HelloWorldApp
 {
   class Hello
   {
      static void Main()
      {
        // This line prints "Hello, World" 
        Console.WriteLine("Hello, World");
      }
   }
 }

The "Hello, World" program starts with a using directive that references the System namespace. Namespaces provide a hierarchical means of organizing C# programs and libraries. Namespaces contain types and other namespaces—for example, the System namespace contains a number of types, such as the Console class referenced in the program, and many other namespaces, such as IO and Collections. A using directive that references a given namespace enables unqualified use of the types that are members of that namespace. Because of the using directive, the program can use Console.WriteLine as shorthand for System.Console.WriteLine.

The Hello class declared by the "Hello, World" program has a single member, the method named Main. The Main method is declared with the static modifier. While instance methods can reference a particular enclosing object instance using the keyword this, static methods operate without reference to a particular object. By convention, a static method named Main serves as the entry point of a C# program.

The line starting with // is a single line comment. C# single line comments start with // and continue to the end of the current line. C# also supports multi-line comments. Multi-line comments start with /* and end with */. The output of the program is produced by the WriteLine method of the Console class in the System namespace. This class is provided by the standard class libraries, which, by default, are automatically referenced by the compiler.
From the code snippet you will notice a semicolon. Each statement or declarations ends with a semicolon. Remember C# is a type safe language and such when you do not end a statement with a semicolon you'll be hit with a compile time error(meaning that your code will not be able to compile and you'll see an indication by a  squiggly line) meaning that something is wrong.
When writing C#, an IDE(Integrated development environment) is used. An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities for software development. It combines various tools into a single interface, streamlining the process of writing and managing code. For C#, Visual studio or visual studio code brings about great experience to users.
**YOUR FIRST HELLO WORLD MAKES YOU A C# DEVELOPER.
SO WELCOME TO C# DEV.**