Intro To C# Programming PDF
Document Details
Woodgrove Bank
Tags
Summary
This document provides an introduction to C# programming, covering its history, evolution, and key features. It touches upon core concepts and methodologies applicable to C#.
Full Transcript
Prof. elective 4 I. INTRODUCTION C# TO IMAGE SLIDE Introduction to C# Setting up the Programming Development Language Environment Basic Syntax and Structure of a C# Progr...
Prof. elective 4 I. INTRODUCTION C# TO IMAGE SLIDE Introduction to C# Setting up the Programming Development Language Environment Basic Syntax and Structure of a C# Program WOODGROVE 2 BANK 1. ORIGINS AND C# DEVELOPMENT: WOODGROVE 3 BANK 1. ORIGINS AND DEVELOPMENT: C# Creation and Microsoft’s Role (2000) Initial Release - C# 1.0 (2002) C# was developed by Microsoft as part of Released with Visual Studio.NET, C# 1.0 its.NET initiative, led by Anders Hejlsberg. focused on core object-oriented principles, The goal was to create a modern, object- garbage collection, exception handling, and a oriented programming language that would be familiar C/C++ style syntax. simple, efficient, and secure, designed for The language was tightly integrated with the.NET Framework. the.NET Framework, leveraging the It was introduced to address some limitations Common Language Runtime (CLR) for cross- in languages like C++ and Java, providing a language compatibility. powerful yet user-friendly tool for developers. WOODGROVE 4 BANK 2. KEY EVOLUTION C# MILESTONES: WOODGROVE 5 BANK 2. KEY EVOLUTION MILESTONES: C# 2.0 (2005) C# 3.0 (2007) Introduced significant language enhancements: Key innovations: Generics: Allowed for creating type-safe LINQ (Language Integrated Query): collections and methods. Allowed querying data (from collections, Anonymous Methods: Helped developers databases, XML, etc.) using C# syntax. write more flexible and concise code. Lambda Expressions: Enabled more concise Iterators: Simplified the process of and functional programming patterns. enumerating through collections. Extension Methods: Allowed adding methods to existing types without modifying them. WOODGROVE 6 BANK 2. KEY EVOLUTION MILESTONES: C# 4.0 (2010) C# 5.0 (2012) Focused on improving interoperability with Major improvement: dynamic programming languages: Asynchronous Programming (async/await): Dynamic Type: Enabled dynamic typing for Revolutionized how developers wrote easier interaction with COM objects, dynamic asynchronous and concurrent code, making it languages like Python, or JavaScript. more readable and maintainable. Named and Optional Parameters: Simplified function calls with default values. WOODGROVE 7 BANK 2. KEY EVOLUTION MILESTONES: C# 6.0 (2015) C# 7.0 and 7.1 (2017) Focused on improving syntax: Enhancements to make the language more Auto-Property Initializers: Simplified expressive: property declarations. Null-Conditional Operators (?.): Tuples: Introduced lightweight data structures for returning multiple values. Reduced the risk of Null Reference Exception by providing concise syntax for Pattern Matching: Allowed more expressive null checks. and functional code by matching patterns in String Interpolation: Simplified string switch statements and other contexts. formatting by embedding expressions Local Functions: Enabled defining functions within string literals. inside other functions for encapsulation. WOODGROVE 8 BANK 2. KEY EVOLUTION MILESTONES: Pattern matching in C# allows you to test whether a value fits a certain pattern and extract data from that value. It simplifies conditional logic by enabling type checks, value checks, and decomposing data structures in a more concise and readable manner. C# 7.0 and 7.1 (2017) Focused on improving syntax: Auto-Property Initializers: Simplified property declarations. Null-Conditional Operators (?.): Reduced the risk of NullReferenceException by providing concise syntax for null checks. String Interpolation: Simplified string formatting by embedding expressions within string literals. WOODGROVE 9 BANK 2. KEY EVOLUTION MILESTONES: C# 8.0 (2019) C# 9.0 (2020) Introduced: Focused on immutability and simplifying code: Nullable Reference Types: Improved null- Records: Introduced for creating immutable, safety by distinguishing between nullable lightweight data objects. and non-nullable reference types. Init-Only Properties: Allowed setting Asynchronous Streams (Async Iterators): properties only during initialization, Enhanced async programming, making it improving immutability. easier to work with data streams. Switch Expressions: Further modernized pattern matching syntax. WOODGROVE 10 BANK 2. KEY EVOLUTION MILESTONES: C# 10.0 (2021) C# 11.0 (2022) Aimed at reducing boilerplate code: Recent improvements include: Global Usings: Simplified managing Raw String Literals: Made working with namespaces by defining common using multi-line and special-character strings easier directives globally across files. without requiring extensive escaping. File-Scoped Namespaces: Allowed for more Generic Math: Provided a more robust compact namespace declarations. system for working with numeric types across generics. Record Structs: Extended records to support value types, offering benefits of records for Required Members: Ensured that certain structs. members are initialized during object creation, further improving immutability practices. WOODGROVE 11 BANK 3. IMPACT OF.NET C# CORE AND.NET 5+ WOODGROVE 12 BANK 3. IMPACT OF.NET CORE AND.NET 5+ NET Core Introduction (2016).NET 5 (2020) and Beyond NET Core Introduction (2016) Microsoft introduced.NET Core to allow C#.NET 5 (2020) and Beyond and.NET to be cross-platform (Windows, With the release of.NET 5, Microsoft macOS, Linux). unified.NET Core and.NET Framework under a single platform. This was a shift from the Windows-only.NET Framework. This allowed C# to be used seamlessly across different platforms and environments, including web development, desktop applications, mobile development, cloud services, and even game development through Unity. WOODGROVE 13 BANK 4. MODERN USE C# AND FUTURE OF WOODGROVE 14 BANK 4. MODERN USE AND FUTURE OF C# C# continues to be a versatile and evolving language, widely used in enterprise applications, web development (with ASP.NET), mobile apps (via Xamarin), and game development (with Unity). Microsoft’s ongoing updates ensure that C# remains modern, flexible, and competitive with newer languages. As of now, C# is evolving towards supporting even more functional programming features, enhancing performance, and simplifying development for cloud-native applications. WOODGROVE 15 BANK Prof. elective 4 II. SETTING UP THE DEVELOPMENT ENVIRONMENT C# https://www.youtube.com/watch?v=HUbWg_11MUY&t=48s&ab_channel=NoAIRex WOODGROVE 17 BANK Prof. elective 4 1. BASIC STRUCTURE OF A C# PROGRAM C# A MINIMAL C# PROGRAM MUST INCLUDE: A namespace (to organize code and avoid name conflicts) A class (the building block of C# programs) A Main method (entry point of the application) WOODGROVE 19 BANK A MINIMAL C# PROGRAM MUST INCLUDE: Explanation of the Example: 1.using System; This directive imports the System namespace, which provides essential classes like Console. It allows us to use its functionalities without fully qualifying the names. 2.namespace HelloWorldApp The namespace is used to group classes and organize code. In larger programs, namespaces help avoid naming conflicts. 3.class Program The class keyword defines a new class. In C#, everything is encapsulated in classes. Program is the name of the class that contains the Main method. 4.static void Main(string[] args) The Main method is the entry point for every C# console application. When the program runs, execution starts here. static: The method is called on the class itself, not on an instance of the class. void: The method does not return a value. string[] args: Represents command-line arguments passed to the program. 5.Console.WriteLine("Hello, World!"); This line prints the string "Hello, World!" to the console. Console is a class in the System namespace that provides methods for input and output. WOODGROVE 20 BANK COMMENTS / VARIABLES AND DATA TYPES / OPERATORS WOODGROVE 21 BANK WOODGROVE 22 BANK 3. FUNCTIONS AND METHODS Methods are blocks of code that perform specific tasks. The Main method is an example of this. WOODGROVE 23 BANK SUMMARY OF C# SYNTAX FEATURES Case-sensitive: C# differentiates between main and Main. Statements end with a semicolon: Each line of executable code is typically followed by a ;. Code is organized in classes: Even the simplest C# program needs at least one class. COMMON ERRORS IN C# SYNTAX Missing Semicolon: Forgetting to terminate a statement with a semicolon will result in a compile-time error. Case Sensitivity: Misnaming method or variable identifiers (e.g., using main instead of Main). Mismatched Braces: Every { must have a corresponding }. WOODGROVE 24 BANK WOODGROVE BANK THANK YOU CUSTOMISE THIS TEMPLATE Template editing instructions and feedback WOODGROVE 26 BANK