Why C# is Not Just About "Enterprise" and Boredom?
\n\nIn the IT world, there is a stereotype: C# is a language for boring enterprise projects, banking systems, and government service portals. But if you set aside prejudices, you'll find that Stack Overflow, Unity, part of Visual Studio, and even JetBrains Rider are written in C#. Let's break down real cases of companies that use C# in production and look at the code behind it.
\n\nThis article is not dry theory, but an analysis of live projects with examples that you can adapt for your own tasks. Let's go.
\n\nCase 1: Stack Overflow — How C# Handles 1 Billion Requests Per Month
\n\nStack Overflow is perhaps the most famous example of using C# in a high-load project. The site processes over 1 billion page views per month, and it runs on ASP.NET MVC (now .NET Core) using Redis and Elasticsearch.
\n\nArchitecture and Why C#?
\nThe Stack Overflow team chose C# for its performance, strong typing, and excellent support for multithreading. A key feature is minimal use of third-party libraries. They wrote their own ORM (Dapper) and their own caching layer.
\n\nCode Example: High-Performance Cache with Redis
\nOne of Stack Overflow's speed secrets is aggressive caching. Here's roughly what their approach to working with Redis looks like via StackExchange.Redis:
public class CacheService\n{\n private readonly IDatabase _cache;\n private readonly TimeSpan _defaultExpiry = TimeSpan.FromMinutes(10);\n\n public CacheService(IConnectionMultiplexer redis)\n {\n _cache = redis.GetDatabase();\n }\n\n public async Task<T> GetOrSetAsync<T>(string key, Func<Task<T>> factory)\n {\n // Attempt to get from cache\n var cached = await _cache.StringGetAsync(key);\n if (cached.HasValue)\n {\n return JsonSerializer.Deserialize<T>(cached);\n }\n\n // If not found — call the factory and save\n var value = await factory();\n var serialized = JsonSerializer.Serialize(value);\n await _cache.StringSetAsync(key, serialized, _defaultExpiry);\n return value;\n }\n}\n\n\nWhy is this cool? They don't just cache everything — they use the cache-aside pattern and set TTL (time-to-live) based on the data type. For example, 30 seconds for the question list, 5 minutes for a user profile.
\n\nCase 2: Unity — C# as a Language for Games and 3D
\n\nUnity is the main game engine for indie developers and large studios. Internally, it is written in C++ (the core), but all game scripting is in C#. Over 50% of mobile games in the world are made with Unity, and that includes not just "Angry Birds," but also Hearthstone or Pokémon GO.
\n\nWhy C# and not C++?
\nUnity chose C# for the balance: it is faster than Python or JavaScript, but safer and simpler than C++. The garbage collector (GC) can be a problem, but in Unity they have learned to control it.
\n\nCode Example: Optimization via Object Pool
\nIn games, objects (bullets, enemies, particles) are often created and destroyed. To avoid freezes due to GC, an Object Pool is used. Here's what it looks like in C#:
\n\npublic class BulletPool : MonoBehaviour\n{\n private Queue<Bullet> _pool = new Queue<Bullet>();\n [SerializeField] private Bullet _bulletPrefab;\n\n public Bullet Get()\n {\n if (_pool.Count > 0)\n {\n var bullet = _pool.Dequeue();\n bullet.gameObject.SetActive(true);\n return bullet;\n }\n return Instantiate(_bulletPrefab);\n }\n\n public void Return(Bullet bullet)\n {\n bullet.gameObject.SetActive(fa