Introduction to the C# programming language

Lesson 1 of 15 · C#

C# (C-Sharp) is a programming language developed by Microsoft as part of the .NET platform. It was first presented in 2000, and its lead designer is Anders Hejlsberg, who had earlier worked on languages such as Turbo Pascal and Delphi.

C# was created at a time when Microsoft wanted to develop a robust, simple and modern language that could compete with Java. Starting with version 1.0, C# evolved quickly, with every new version bringing advanced features such as generics, LINQ (Language Integrated Query), async/await and other modern capabilities.

Uses

Today C# is widely used to develop many kinds of applications:

  • Desktop applications: C# is often used to develop Windows applications with Windows Forms or WPF (Windows Presentation Foundation).
  • Web applications: ASP.NET, which is part of the .NET platform, makes it possible to develop dynamic web applications in C#.
  • Games: C# is very popular in video game development, especially with the Unity game engine, which uses C# as its main scripting language.
  • Mobile applications: With Xamarin, C# is used to develop mobile applications that can run on iOS, Android and Windows.
  • Cloud and IoT applications: Microsoft Azure and other cloud platforms offer excellent support for C# applications, and the language is also used to develop Internet of Things (IoT) solutions.

Comparison with Java

C# and Java are very similar languages, since both were inspired by C++ and designed as robust solutions for developing many kinds of software.

  • Syntax: C# and Java share a similar syntax, but C# is more flexible in some respects (for example, support for delegates, events and properties).
  • Platform: Java is platform independent thanks to the JVM (Java Virtual Machine), while C# was originally tied to Windows. However, with .NET Core (now .NET), C# has become a cross-platform language.
  • Performance: Both languages perform similarly in many scenarios, although this depends on the implementation and the specific platform.
  • Ecosystem: Java has a rich ecosystem in the world of enterprise applications and Android development, while C# dominates in the world of Windows applications and games.

Comparison with other programming languages

  • C++: C# is easier to learn and use than C++, although it offers less control over the hardware and performance.
  • Python: Python is simpler for beginners and popular in fields such as data science and artificial intelligence, while C# is more robust for developing large systems.
  • JavaScript: JavaScript is used mainly for web frontend development, while C# is more oriented towards backend and desktop applications.

C# is a powerful, flexible language that makes it possible to develop a wide range of software solutions, and thanks to its rich standard library and its integration with the .NET platform it remains one of the most important languages in modern software development.

What is specific to C# and sets it apart from other programming languages

C# has several specific features that set it apart from other programming languages:

1. Integration with the .NET ecosystem:

C# is closely tied to the .NET platform, which makes it easy to develop applications for Windows as well as for the web, mobile devices and the cloud. .NET provides a rich set of libraries and tools that make application development easier, including ASP.NET for web applications and Xamarin for mobile applications.

2. Simple syntax and readability:
C# was designed to be easy to learn and use, with a focus on readable code. It has similarities with C++ and Java, but its syntax is often simplified and less error-prone.

3. Strong typing and type safety:

C# uses strict typing, which means that data types must be clearly defined. This reduces the chance of errors in the code and allows better optimizations at compile time.

4. Garbage Collection:

C# manages memory automatically through the garbage collection mechanism, which automatically frees memory that is no longer in use. This reduces the chance of memory leaks and other memory management problems.

5. Language Integrated Query (LINQ):

LINQ lets you write queries over collections of data directly in C# code, which makes it easier to work with databases, XML documents and other data structures.

6. Asynchronous programming:

C# supports simple mechanisms for asynchronous programming with the `async` and `await` keywords, which make it easier to handle operations that take a long time, such as I/O operations, without blocking the main thread.

7. Support for modern paradigms:

C# keeps evolving and includes modern paradigms such as functional programming, through its support for lambda expressions, anonymous methods and other functional concepts.

8. Cross-platform development:

With the development of .NET Core, now known as .NET 5/6/7, C# has become a cross-platform language, which means that applications written in C# can run on Windows, macOS and Linux.

9. A large community and support:

C# has a large community of programmers and support from Microsoft, which means plenty of resources, documentation, tutorials and ready-made solutions available on the internet.

These features make C# a flexible and powerful tool for developing a wide range of applications, from business software to games, web applications and mobile applications.

What do you need to write C# programs today?

To write and run C# programs, here is what you need:

1. The .NET SDK: This is the basic development kit for C#. You can download it from Microsoft's site (https://dotnet.microsoft.com/download). The SDK includes the .NET runtime, the compiler and other tools needed to develop applications in C#.

2. An IDE (Integrated Development Environment):

- Visual Studio: The most popular IDE for C# development, offering a comprehensive set of tools for developing, testing and deploying C# applications. Microsoft Visual Studio comes in several editions, including the free Community edition, which is enough for most needs.

- Visual Studio Code: A lighter editor that can be used for C# development with the C# extension. This editor is ideal for smaller projects or for those who prefer a minimalist tool.

3. A compiler: If you do not use an IDE, you can compile C# code by hand with the command `dotnet build` or `csc` (the C# Compiler), which is part of the .NET SDK.

4. Git: A useful tool for version control of your code. Visual Studio and Visual Studio Code integrate with Git, so you can manage your code directly from the IDE.

5. Additional libraries and packages: Through the .NET package manager NuGet you can download additional libraries that make it easier to develop certain features.

How to start programming in C#

It is best to start with free tools that are well suited for learning:

  1. Visual Studio Community Edition
  2. Visual Studio Code (VS Code)

Visual Studio Community Edition

  • Description: Visual Studio is a powerful and comprehensive IDE specialized for C# development. The Community Edition is a free version that provides all the tools you need for learning and developing in C#.
  • Advantages:
    • Integration with .NET: Visual Studio is very well integrated with the .NET framework, which is the foundation for developing C# applications.
    • Debugging tools: It has extremely powerful debugging tools, which are useful for beginners.
    • Development for different platforms: You can develop applications for Windows, the web, mobile devices, games (with Unity) and much more.
    • Rich documentation and community: Visual Studio has extensive documentation and a large user community, which helps when you are starting to learn.
  • Platforms: Windows (there is also Visual Studio for Mac for macOS users).
  • Download: Visual Studio Community

Visual Studio Code (VS Code)

  • Description: If you prefer a lighter, highly customizable editor, you can use Visual Studio Code with extensions for C#. This is a more flexible option and it can be used on several platforms (Windows, macOS, Linux).
  • Extensions:
    • C#: Adds support for the C# language.
    • .NET Core: Supports the development of .NET Core applications.
  • Download: VS Code

Check your knowledge

Open the quiz

Introduction to C#

1. Which company developed the C# language?




2. Which platform does C# run on?




3. What is C# NOT often used for?




4. What automatically frees memory that is no longer used?