C# Introduction PDF - Learn C# Programming
Document Details

Uploaded by SociableNeptune
Northeastern College
Tags
Summary
This document provides an introduction to C# programming and the .NET Framework. It covers topics such as the .NET architecture, components, and design principles, alongside a basic 'Hello World' C# program. It offers insights into potential career outcomes and the learning order for C# development.
Full Transcript
C# INTRODUCTION What is C#? C# (C Sharp) is a general purpose, multi-paradigm programming language developed by Microsoft that runs on the.NET Framework. C# is widely used for building mobile applications, games and windows applications. What is.Net Framework?.Net Framework is a software devel...
C# INTRODUCTION What is C#? C# (C Sharp) is a general purpose, multi-paradigm programming language developed by Microsoft that runs on the.NET Framework. C# is widely used for building mobile applications, games and windows applications. What is.Net Framework?.Net Framework is a software development platform developed by Microsoft for building and running Windows applications. The.Net framework consists of developer tools, programming languages, and libraries to build desktop and web applications. It is also used to build websites, web services, and games..Net Framework Architecture The basic architecture of the.Net framework is as shown below. is a programming model for the.Net platform that provides an execution environment and integration with various programming languages for simple development and deployment of various Windows and desktop applications. It consists of class libraries and reusable components..NET Components The CLI has the following key features: 1. The “Common Language Infrastructure” or CLI is a a. Exception Handling – Exceptions platform in.Net architecture are errors which occur when the on which the.Net programs application is executed. are executed. b. Garbage Collection – Garbage collection is the process of removing unwanted resources when they are no longer required. Language 1 The first level is the programming language itself, the most common ones are VB.Net and C#. 1 Language 2 Compiler There is a compiler which will be separate for each programming language. So underlying the VB.Net language, there will be a separate VB.Net compiler. Similarly, for C#, you will have another compiler. 1 Language 2 Compiler This is the final layer in.Net which would be used to run a.net program developed in any programming language. So the Common Language Interpreter subsequent compiler will send the program 3 to the CLI layer to run the.Net application..NET Components 2. Class Library For example, there is a class library with methods to handle all The.NET Framework file-level operations. So there is a includes a set of standard method which can be used to read the text from a file. Similarly, there class libraries. A class is a method to write text to a file. library is a collection of methods and functions that can be used for the core purpose..NET Components WinForms – This is used for developing Forms-based applications, 3. Languages which would run on an end user machine. Notepad is an example of a The types of applications client-based application. that can be built in the.Net framework is classified ASP.Net – This is used for developing web-based applications, which are broadly into the following made to run on any browser such as categories. Internet Explorer, Chrome or Firefox. ADO.Net – This technology is used to develop applications to interact with Databases such as Oracle or Microsoft SQL Server. LOGO.Net Framework Design Principle Interoperability Portability Security Memory management Simplified deployment LOGO.Net Framework DesignPrinciple Interoperability The.Net framework provides a lot of backward support. Suppose if you had an application built on an older version of the.Net framework, say 2.0. And if you tried to run the same application on a machine which had the higher version of the.Net framework, say 3.5. The application would still work. This is because with every release, Microsoft ensures that older framework versions get well with the latest version. LOGO.Net Framework DesignPrinciple Portability Applications built on the.Net framework can be made to work on any Windows platform. And now in recent times, Microsoft is also envisioning to make Microsoft products work on other platforms, such as iOS and Linux. LOGO.Net Framework DesignPrinciple Security The.NET Framework has a good security mechanism. The inbuilt security mechanism helps in both validation and verification of applications. Every application can explicitly define their security mechanism. Each security mechanism is used to grant the user access to the code or to the running program. LOGO.Net Framework DesignPrinciple Memory management The Common Language runtime does all the work or memory management. The.Net framework has all the capability to see those resources, which are not used by a running program. It would then release those resources accordingly. This is done via a program called the “Garbage Collector” which runs as part of the.Net framework. The garbage collector runs at regular intervals and keeps on checking which system resources are not utilized, and frees them accordingly. LOGO.Net Framework.Net Framework DesignPrinciple DesignPrinciple Memory management is the process of controlling and coordinating computer memory, assigning portions known as blocks to various running programs to optimize the overall performance of the system. LOGO.Net Framework DesignPrinciple Simplified deployment The.Net framework also have tools, which can be used to package applications built on the.Net framework. These packages can then be distributed to client machines. The packages would then automatically install the application. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; First C# program. namespace MyProgram { class Program { // Main Program static void Main(string[] args) { Console.WriteLine("Congratulations, you wrote your first Program"); Console.ReadKey(); } } } 1. Comments Comments are used for explaining code and are used in similar manner as in Java or C or C++. Compilers ignore the comment entries and does not execute them. Comments can be of single line or multiple lines. Single line Comments: Syntax: // Single line comment Multi line comments: Syntax: 2. using System using keyword is used to include the System namespace in the program. are used to import any libraries Libraries - are basically set of pre-built functions that we can directly use in our code. namespace declaration A namespace is a collection of classes. The example namespace contains the class Program. 3. class The class contains the data and methods to be used in the program. Methods define the behavior of the class. Class Program has only one method Main similar to JAVA. 4. static void Main(): static keyword tells us that this method is accessible without instantiating the class. 5. void keywords - tells that this method will not return anything. Main() method is the entry-point of our application. In our program, Main() method specifies its behavior with the statement Console.WriteLine(“Congratulations, you wrote your first Program”);. 6. Console.WriteLine() WriteLine() is a method of the Console class defined in the System namespace. 7. Console.ReadKey() This is for the VS.NET Users. This makes the program wait for a key press and prevents the screen from running and closing quickly. Thank You!