C# 12.0
C# 12.0
C# Language Basics :
===================================================================================
=
Many commonly used types—including the Console class—reside in the System
namespace.
System.Text namespace contains types for handling text, and System.IO contain types
for input output.
Compilation :
The C# compiler compiles source code (a set of files with the .cs extension) into
an assembly. An assembly is the unit of packaging and deployment in .NET.
An assembly can be either an application or a library.
Comments
C# offers two different styles of source-code documentation: single-line
comments and multiline comments.
A single-line comment begins with a double forward slash and continues until
the end of the line;
Type Basics
A type defines the blueprint for a value.
In this example, we use two literals of type int with values 12 and 30.
We also declare a variable of type int whose name is x: int x = 12 * 30;
Console.WriteLine (x);
A variable denotes a storage location that can contain different values over
time. In contrast, a constant always represents the same value. const int y = 360;
Predefined types are types that are specially supported by the compiler.
The int type is a predefined type for representing the set of integers that
fit into 32 bits of memory, from −231 to 231 − 1, and is the default type for
numeric literals within this range.
The string type represents a sequence of characters.
The predefined bool type has exactly two possible values: true and false.
Custom Types
Just as we can write our own methods, we can write our own types. In this
next example, we define a custom type named UnitConverter—a class that serves as a
blueprint for unit conversions:
An array (such as string[]) represents a fixed number of elements of a particular
type. Arrays are specified by placing square brackets after the element type.
Arrays
An array represents a fixed number of variables (called elements) of a
particular type. The elements in an array are always stored in a contiguous block
of memory,providing highly efficient access. An array is denoted with square
brackets after the element type:
char[] vowels = new char[5]; // Declare an array of 5 characters
Square brackets also index the array, accessing a particular element by
position:
vowels[0] = 'a';
vowels[1] = 'e';
vowels[2] = 'i';
vowels[3] = 'o';
vowels[4] = 'u';
Console.WriteLine (vowels[1]); // e
An array itself is always a reference type object, regardless of the element
type. For instance,
the following is legal: int[] a = null;