Category «C# Language Basics»

Strings in C#

The System.String, or string class, is a reference type that is represented internally by a sequence of 16-bit Unicode characters. Unlike other reference types, C# treats a string as a primitive type: It can be declared as a constant, and it can be assigned a literal string value. String Literals Literal values assigned to string …

Operators: Arithmetic, Logical, and Conditional in C#

The C# operators used for arithmetic operations, bit manipulation, and conditional program flow should be familiar to all programmers. This section presents an overview of these operators that is meant to serve as a syntactical reference. Arithmetic Operators Table 2-4 summarizes the basic numerical operators. The precedence in which these operators are applied during the …

C# Primitive Data Types

The next three sections of this chapter describe features that you’ll find in most programming languages: variables and data types, operators, expressions, and statements that control the flow of operations. The discussion begins with primitives. As the name implies, these are the core C# data types used as building blocks for more complex class and …

Arrays in C#

C#, like most programming languages, provides the array data structure as a way to collect and manipulate values of the same type. Unlike other languages, C# provides three types of arrays. One is implemented as an ArrayList object; another as a generic List object; and a third is derived from the System.Array class. The latter, …

Loops in C#

C# provides four iteration statements: while, do, for, and foreach. The first three are the same constructs you find in C, C++, and Java; the foreach statement is designed to loop through collections of data such as arrays. while loop Syntax: while ( boolean expression ) { body } The statement(s) in the loop body …