C# Programming Fundamentals: Key Concepts by Chapter

C# Programming: Key Concepts by Chapter

Chapter 1: C# Basics

  • Programming Language: System of words and grammar for computer operations.
  • Program: Instructions directing computer actions.
  • Software:
    • System Software: Operates the computer.
    • Application Software: Enables user tasks.
  • Machine Language: Binary code (1s and 0s).
  • High-Level Programming Language: Uses understandable vocabulary.
    • Syntax: Language rules.
      • Syntax Error: Incorrect language usage, found during compilation.
      • Source Code: Written statements in high-level language.
      • Compiler: Translates high-level to machine language.
      • Logic: Correct execution order for desired results.
        • Logic Error: Found through testing, not compilation.

Object-Oriented Programming

  • Object-Oriented: Supports classes and objects.
    • OOP: Class + object.
    • Procedural: Function + variable.
    • Class: Describes potential objects with attributes and behaviors.
      • Attributes: Properties, characteristics, or data fields.
      • Behaviors: Methods representing actions.
    • Upper Camel Casing: Naming convention (e.g., TVShows).
    • Object: Instance of a class (e.g., Student vs. John).
    • Object-Oriented Approach: Define objects for tasks, develop classes.
      • GUI: Graphical user interaction.
      • Computer Simulation: Recreates real-world activities.
      • C# Language: Employs OOP; all data treated as objects.

C# Fundamentals

  • Main() Method: Entry point of the program.
    • Application Class: Contains Main().
    • Non-application Class: Lacks Main().
  • Namespace: Groups similar classes.
  • Method Header: Includes name and parameters.
  • Method Body: Instructions executed, enclosed in {}.
  • Whitespace: Blank lines and spaces.
  • Static: Main() executed through a class.
  • Void: Method returns nothing, executes internal instructions.

Miscellaneous

  • Comments:
    • Line Comment: Starts with //.
    • Block Comment: Starts with /* and ends with */.
  • Visual Studio: Integrated Development Environment (IDE) for command execution.

Chapter 2: Variables and Data Types

  • Variable: Named location holding different values over time (e.g., int = 21).
  • Data Type: Describes format/size of data and operations.
  • Constant: Unchangeable data item post-compilation (e.g., const int age = 21).
  • Intrinsic Types: Basic data types (e.g., int, double, char, string, bool).
    • Numerical Types:
      • Byte: 0-255.
      • Short: -32,768 to 32,767.
      • Int: -2,147,483,648 to 2,147,483,647.
      • Long: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
      • Float: 32-bit decimal numbers.
      • Double: 64-bit decimal numbers.
      • Decimal: 128-bit decimal numbers, ideal for financial calculations.
  • Variable Name: Uses lower camel casing (e.g., myAge).
  • Variable Declaration: Includes data type, name, and assignment operator (e.g., int myAge = 25).
    • Initialization: Assignment at declaration; subsequent assignments do not require data type.
    • Usage: Variables must be initialized before use.
    • Multiple Declarations: Can declare multiple variables of the same type in one line.

Displaying Variables

  • Write() vs WriteLine():
    • Write: Outputs on the same line.
    • WriteLine: Outputs and moves to the next line.
  • Standard Numeric Format Strings: Format specifiers for output (e.g., C for currency).
    • Format Specifiers: C (Currency), D (Decimal), E (Exponential), F (Fixed Point), G (General), N (Number), P (Percent), R (Round Trip), X (Hexadecimal).
    • Precision Specifier: Controls digit count in output.

Operators and Conversion

  • Arithmetic Operators: Addition (+), Subtraction (-), Multiplication (*), Division (/), Remainder (%).
  • Shortcut Operators: +=, -=, *=, /=, %=.
  • Prefix/Postfix: Pre-increment (++x), Post-increment (x++), Pre-decrement (–x), Post-decrement (x–).
  • Numeric Type Conversion: Implicit (automatic) and Explicit (manual) casting.
  • Parsing: Breaking a string into a numeric equivalent.

Chapter 4: Logic and Decision Structures

  • Logic Planning: Unicode values, Pseudocode, and Flowcharts.
  • Sequence Structure: Steps follow unconditionally.
  • Decision Structure: Chooses actions based on true/false values.
  • If Statements: Single alternative, block statements, nested if, and compound expressions.
  • Logical Operators: AND (&&), OR (||), NOT (!).
  • Switch Statement: Tests a variable against multiple cases using Case, Break, and Default.

Chapter 5: Loops and Iteration

  • Loops: Structures for repeated execution of statements.
  • While Loops: Continues while condition is true.
  • For Statement: Creates definite loops using initialization, testing, and updating.
  • Do Loop: Posttest loop ensuring at least one execution.
  • Nested Loops: Inner loop contained within an outer loop.
  • Optimization: Accumulating totals, avoiding unnecessary operations, and loop fusion.