C# is also available in non-Microsoft implementations (most notably, Mono).
Versions 1.0/1.2 and 2.0 of C# were submitted and approved as both ECMA and ISO/IEC standards. As of December 2010, there are no ECMA or ISO/IEC specifications for C# 3.0 and 4.0, however language specifications are available from Microsoft (3.0 and 4.0 respectively).
The language's type-system was originally static, with only explicit variable declarations allowed. However, the introduction of var (C# 3.0) and dynamic (C# 4.0) allow it to use type-inference for implicit variable typing, and to consume dynamic type-systems, respectively. Delegates (especially with lexical-closure support for anonymous-methods (C# 2.0) and lambda-expressions (C# 3.0)) allow the language to be used for functional programming.
Compilation is usually to the Common Intermediate Language (CIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR); however, options like Ngen (.NET) and AOT (Mono) mean this isn't the only option. Additionally, some frameworks (e.g. the Micro Framework) act as CIL interpreters, with no JIT.
Perhaps unusually, generics in C# are provided (in part) by the runtime, unlike (for comparison) C++ templates, or Java's generics (which use type-erasure).
With the combination of Microsoft .NET for Windows (desktop/server), Mono (desktop/server/mobile), Silverlight / Moonlight (browser/mobile), Compact Framework (mobile), and Micro Framework (embedded devices), it is available for a wide range of platforms.
In November 2014, Microsoft announced the decision to Open Source .NET with Apache 2.0 Open Source licensing and to begin supporting iOS, Linux, and Android in addition to Windows as platforms for .NET 2015 (5.0) and ASP.NET 5.0. As a result C# can now target all these platforms using a single code base through Visual Studio 2015 (currently available for preview).
Hello World
using System;
class Hello
{
static void Main()
{
Console.WriteLine("Hello, World");
}
}
FAQs on Stack Overflow
- What are the correct version numbers for C#?
- Why is
Randomgiving the same results every time? - Captured variables in loops
- In C#, is it possible to cast a
List<Child>toList<Parent>? - Does C# pass objects by reference?
- Why does the compiler complain about my conditional expression (
a == b ? x : y)? - Why do I get a
NullReferenceException? (Object reference not set to instance of object) - http://stackoverflow.com/questions/24812679
- What's new in C# 4.0?
- What's new in .NET 4.5?
- What's new for C# in Visual Studio 2012?
Resources
- Specification
- Wikipedia Article
- Eric Lippert's old blog || Eric Lippert's new blog
- Jon Skeet's blog
- James Michael Hare's C#/.NET Little Wonders & Little Pitfalls series
- Programming Guide
- Getting Started with Visual C#
- C# Fundamentals: Development for Absolute Beginners
- Visual C# .Net for Beginners
- csharp.2000things
- Dot Net Perls
Books
- CLR via C#
- C# 5.0 in a Nutshell: The Definitive Reference
- C# in Depth
- Accelerated C#
- Head First C#
- The C# Programming Language (3rd Edition, 4th Edition)
- Framework Design Guidelines
- Essential C# (4.0 (3rd Edition), 5.0 (4th Edition))
- Pro C# 2010 and the .NET 4 Platform
- [MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0 Foundation] 33
- C# How to Program
- Visual C# .NET Step by Step
- Programming Microsoft Windows with C#
- C# 4.0 Unleashed
- Pro C# 5.0 and the .NET 4.5 Framework (Professional Apress)
- Learning C# 3.0
- Starting out with Visual C# 2012 (with CD-Rom) (3rd Edition)
- Programming C# 5.0 — Building Windows 8, Web, and Desktop Applications for the .NET 4.5 Framework
- C# 4.0 The Complete Reference
- [C# Design Pattern Essentials] 43
- Programming C# 5.0 - Building Windows 8, Web, and Desktop Applications for the .NET 4.5 Framework