C#
Developers use C# (pronounced “C sharp”) to build web services, desktop apps, and games. The compiler checks types before the program runs, and most C# applications run on .NET.
Also known as: .NET, си шарп
C# is the language; .NET is the platform
C# is a statically typed programming language developed by Microsoft. If a method expects an int and you pass it a string, the compiler rejects the call rather than waiting for the program to fail at runtime. You don't always need to write the type yourself: in var count = 3, the compiler infers int. The variable can't later hold a string.
.NET supplies the runtime, standard libraries, and build tools that C# developers typically use. It also supports other languages, such as F#. Modern .NET runs on Linux, macOS, and Windows; the older .NET Framework is Windows-only.
From C# source to running code
A standard build translates C# into Intermediate Language (IL) and packages it with type metadata in an assembly. In a typical .NET process, the just-in-time compiler turns methods into machine code as they're needed. Native AOT is an alternative that compiles the application to machine code when it is published.
.NET's garbage collector reclaims memory from objects the program can no longer reach. That doesn't mean it closes a file as soon as you're done reading it. A using statement calls Dispose on a disposable resource when control leaves the block, even if the code throws an exception.
Example: an asynchronous service call
using System.Net.Http;
using System.Threading.Tasks;
static async Task<string> LoadCatalogAsync(HttpClient client)
{
string json = await client.GetStringAsync("/catalog");
return json;
}
The caller supplies an HttpClient with a base address configured. GetStringAsync starts the request and returns a Task<string> representing its eventual result. If the result isn't ready, await suspends the method without blocking a thread while the response is pending. Once the task succeeds, json holds the response text. await doesn't create a new thread or parse the JSON.
Where C# shows up in practice and interviews
Backend teams use ASP.NET Core to route HTTP requests and build APIs, and often use Entity Framework Core for database access. C# is also used for background workers, desktop software, and Unity games.
Interviews often ask you to predict what a small snippet will do. For example, assigning a class variable to another variable copies the reference, so changing the object through either variable is visible through the other. Assigning a struct copies its value, but any reference fields inside it still refer to the same objects. Reasoning about what gets copied is more reliable than guessing whether something lives on the stack or heap.