C# 8.0 Pocket Reference

C# is a general-purpose, type-safe, object-oriented programming language, the goal of which is programmer productivity. To this end, the language balances simplicity, expressiveness, and performance. C# 8 is designed to work the Microsoft .NET Core 3 runtime, and .NET Standard 2.1 (whereas C# 7 was designed to work with the Microsoft .NET Framework 4.6/4.7/4.8 as well as .NET Core 2.x and .NET Standard 2.0).

Note

The programs and code snippets in this book mirror those in Chapters 2 through 4 of C# 8.0 in a Nutshell and are all available as interactive samples in LINQPad. Working through these samples in conjunction with the book accelerates learning in that you can edit the samples and instantly see the results without needing to set up projects and solutions in Visual Studio.

To download the samples, click the Samples tab in LINQPad and then click “Download more samples.” LINQPad is free—go to http://www.linqpad.net.

A First C# Program

Here is a program that multiplies 12 by 30 and prints the result, 360, to the screen. The double forward slash indicates that the remainder of a line is a comment:

using System;                 // Importing namespace

class Test                    // Class declaration
{
  static void Main()          // Method declaration
  {
    int x = 12 * 30;          // Statement 1
    Console.WriteLine (x);    // Statement 2
  }                           // End of method
}                             // End of class

At the heart of this program lie two statements. Statements in C# execute sequentially and are terminated by a semicolon. The first statement ...

Get C# 8.0 Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.