Summary

Section 3.2.1 Comments

  • You may insert comments to document apps and improve their readability. The C# compiler ignores comments.

  • A comment that begins with // is called a single-line comment, because it terminates at the end of the line on which it appears.

  • Comments delimited by /* and */ can be spread over several lines.

  • A programming language’s syntax specifies rules for creating a proper app in that language.

Section 3.2.2 using Directive

  • A using directive helps the compiler locate a type that’s used in an app.

  • C# provides a rich set of predefined classes that you can reuse rather than “reinventing the wheel.” These classes are grouped into namespaces—named collections of classes.

  • Collectively, C#’s predefined namespaces are referred to as the .NET Framework Class Library.

Section 3.2.3 Blank Lines and Whitespace

  • You may use blank lines and space characters to make apps easier to read. Together, blank lines, space characters and tab characters are known as whitespace. Space characters and tabs are known specifically as whitespace characters. Whitespace is ignored by the compiler.

Section 3.2.4 Class Declaration

  • Every app in C# consists of at least one class declaration that’s defined by the programmer (also known as a user-defined class).

  • Keywords are reserved for use by C# and are always spelled with all lowercase letters.

  • Keyword class introduces a class declaration and is immediately followed by the class name.

  • By convention, all class names in C# begin with a capital letter and capitalize the first letter of each word they include (e.g., SampleClassName). This convention is known as Pascal Case.

  • A C# class name is an identifier—a series of characters consisting of letters, digits, and underscores (_) that does not begin with a digit and does not contain spaces.

  • C# is case sensitive—that is, uppercase and lowercase letters are distinct.

  • The body of every class declaration is delimited by braces, { and }.

Section 3.2.5 Main Method

  • Method Main is the starting point of every C# app and is typically defined as:

    
    static void Main()
    
  • Methods are able to perform tasks and can return information when they complete their tasks. Keyword void indicates that a method will perform a task but will not return a value.

Section 3.2.6 Displaying a Line of Text

  • Statements instruct the computer to perform actions.

  • A sequence of characters in double quotation marks is called a string, a character string, a message or a string literal.

  • The Console class allows C# apps to read and display characters in the console window.

  • Method Console.WriteLine displays its argument in the console window, followed by a newline character to position the screen cursor to the beginning of the next line.

  • Most statements end with a semicolon.

Section 3.3.1 Creating the Console App

  • Visual Studio provides many ways to personalize your coding experience. You can modify the editor settings to display line numbers or set code indentation.

Section 3.3.3 Writing Code and Using IntelliSense

  • As you type characters, in some contexts Visual Studio highlights the first member that matches all the characters typed, then displays a tool tip containing a description of that member. This IDE feature is called IntelliSense.

  • When you type code, the IDE either applies syntax-color highlighting or generates a syntax error.

Section 3.4.1 Displaying a Single Line of Text with Multiple Statements

  • Console.Write displays its argument and positions the screen cursor immediately after the last character displayed.

Section 3.4.2 Displaying Multiple Lines of Text with a Single Statement

  • C# combines a backslash () in a string with the next character in the string to form an escape sequence. The escape sequence (newline) positions the cursor to the beginning of the next line.

Section 3.5 String Interpolation

  • A variable declaration statement specifies the name and type of a variable.

  • A variable is a location in the computer’s memory where a value can be stored for use later in an app. Variables must be declared with a name and a type before they’re used.

  • A variable’s name enables the app to access the value of the variable in memory. A variable name can be any valid identifier.

  • Like other statements, variable declaration statements end with a semicolon (;).

  • C# 6’s string interpolation enables you to insert values into a string literal.

  • An interpolated string must begin with a $ (dollar sign). Then, you can insert interpolation expressions enclosed in braces, {}, anywhere between the interpolated string’s quotes ("").

  • When C# encounters an interpolated string, it replaces each braced interpolation expression with the corresponding value.

Section 3.6.1 Declaring the int Variable number1

  • Integers are whole numbers, such as –22, 7, 0 and 1024.

  • Type int is used to declare variables that will hold integer values. The range of values for an int is –2,147,483,648 to +2,147,483,647.

  • Types float, double, and decimal specify real numbers, and type char specifies character data. Real numbers are numbers that may contain decimal points, such as 3.4, 0.0 and –11.19. Variables of type char data represent individual characters, such as an uppercase letter (e.g., A), a digit (e.g., 7), a special character (e.g., * or %) or an escape sequence (e.g., the newline character, ).

  • Types such as int, float, double, decimal, and char are often called simple types. Simple-type names are keywords; thus, they must appear in all lowercase letters.

Section 3.6.3 Prompting the User for Input

  • A prompt directs the user to take a specific action.

  • Console method ReadLine obtains a line of text from the keyboard for use in an app.

  • int method Parse extracts an integer from a string of characters.

  • The assignment operator, =, enables the app to give a value to a variable. Operator = is called a binary operator because it has two operands. An assignment statement uses an assignment operator to assign a value to a variable.

Section 3.6.6 Summing number1 and number2

  • Portions of statements that have values are called expressions.

Section 3.7 Memory Concepts

  • Variable names correspond to locations in the computer’s memory. Every variable has a name, a type, a size and a value.

  • Whenever a value is placed in a memory location, the value replaces the previous value in that location. The previous value is lost.

Section 3.8 Arithmetic

  • Most apps perform arithmetic calculations. The arithmetic operators are + (addition), - (subtraction), * (multiplication), / (division) and % (remainder).

  • If both operands of the division operator (/) are integers, the result is an integer.

  • The remainder operator, %, yields the remainder after division.

Section 3.8.1 Arithmetic Expressions in Straight-Line Form

  • Arithmetic expressions in C# must be written in straight-line form.

Section 3.8.2 Parentheses for Grouping Subexpressions

  • If an expression contains nested parentheses, the innermost set of parentheses is evaluated first.

Section 3.8.3 Rules of Operator Precedence

  • C# applies the operators in arithmetic expressions in a precise sequence determined by the rules of operator precedence.

  • Associativity determines whether operators are applied from left to right or right to left.

Section 3.8.5 Redundant Parentheses

  • Redundant parentheses in an expression can make an expression clearer.

Section 3.9 Decision Making: Equality and Relational Operators

  • A condition is an expression that can be either true or false. C#’s if statement allows an app to make a decision based on the value of a condition.

  • Conditions in if statements can be formed by using the equality (== and !=) and relational (>,

    <, >= and <=) operators.

  • An if statement always begins with keyword if, followed by a condition in parentheses and a body, which you should always enclose in braces ({}).

  • An empty statement is a statement that does not perform a task.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset