Chapter 1 cgc
Chapter 1 cgc
NET Framework
2
Introduction to C#
❖ C# could theoretically be compiled to machine code, but in real life, it’s always used in
combination with the .NET framework.
❖ Therefore, applications written in C#, requires the .NET framework to be installed on the
computer running the application.
❖ While the .NET framework makes it possible to use a wide range of languages, C# is sometimes
referred to as THE .NET language, perhaps because it was designed together with the
framework.
❖ Language interoperability is the ability of code to interact with code that is written by using a
different programming language.
3
Features of C#
❖ Type-safety Checking
❖ Object-oriented Programming
❖ Garbage Collection
❖ Generic Types and Methods
❖ Iterators
❖ Methods with named Arguments
❖ Methods with optional Arguments
❖ Static Classes
4
Features of C#
❖ Nullable Types
❖ Auto-implemented Properties
❖ Accessor Accessibility
❖ Anonymous Methods
❖ Parallel Computing
❖ Auto-implemented Properties
❖ Partial Classes
5
Features of C#
❖ Object-oriented Programming: Focuses on objects so that code written once can be reused. This helps
reduce time and effort on the part of developers.
❖ Type-safety Checking: Checked the overflow of types because uninitialized variables cannot be used in
C# as C# is a case-sensitive language.
❖ Garbage Collection: Performs automatic memory management from time to time and spares the
programmer the task.
❖ Generic Types and Methods: Are a type of data structure that contains code that remains the same
throughout but the data type of the parameters can change with each use.
❖ Iterators: Enable looping (or iterations) on user-defined data types with the for each loop.
❖ Static Classes: Contain only static members and do not require instantiation.
❖ Partial Classes: Allow the user to split a single class into multiple source code (.cs) files.
6
Features of C#
❖ Anonymous Methods: Enable the user to specify a small block of code within the delegate declaration.
❖ Methods with named Arguments: Enable the user to associate a method argument with a name rather
than its position in the argument list.
❖ Methods with optional Arguments: Allow the user to define a method with an optional argument with a
default value.
❖ Nullable Types: Allow a variable to contain a value that is undefined.
❖ Accessor Accessibility: Allows the user to specify the accessibility levels of the get and set accessors.
❖ Auto-implemented Properties: Allow the user to create a property without explicitly providing the
methods to get and set the value of the property.
❖ Parallel Computing: Support for parallel programming using which develop efficient, fine-grained, and
scalable parallel code without working directly with threads or the thread pool.
7
Object Orientation
● C# is a rich implementation of the object-orientation paradigm, which includes encapsulation, abstraction, inheritance and
polymorphism.
● The features of C# from an object-oriented perspective are:
● Unified type system:
○ The fundamental building block in C# is an encapsulated unit of data and functions called a type.
○ C# has a unified type system, where all types ultimately share a common base type. This means that all types, whether they
represent business objects or are primitive types such as numbers, share the same basic functionality.
○ For example, an instance of any type can be converted to a string by calling its ToString method.
● Classes and interfaces:
○ In a traditional object-oriented paradigm, the only kind of type is class.
○ In C# , there are several other kinds of types, one of which is an interface.
○ An interface is like a class, except that it only describe members. The implementation for those members come from types that
implement the interface.
○ Interfaces are particularly useful in scenarios where multiple inheritance is required.
○ C # doesn’t support multiple inheritance of classes.
8
Object Orientation
9
Type Safety
● C# is primarily a type-safe language, meaning that instances of types can interact only through protocols
they define, thereby ensuring each type’s internal consistency.
● For instance, C# prevents you from interacting with a string type as though it were an integer type.
● More specifically, C# supports static typing , meaning that the language enforces type safety at compile
time. This in addition to type safety being enforced at run-time.
● Static typing eliminates a large class of errors before a program is even run. It shifts the burden away
from runtime unit tests onto the compiler to verify that all the types in a program fit together correctly.
This makes large programs much easier to manage, more predictable, and more robust. Furthermore,
static typing allows tools such as IntelliSense in Visual Studio to help you write a program, since it knows
for a given variable what type it is, and hence what methods you can call on that variable.
● C# also called a strongly typed language because its types rules are very strict.
10
Memory Management
11
Platform Support
● Historically, C# was used almost entirely for writing code to run on Windows platforms.
● Recently, however, Microsoft and other companies have invested in other platforms, including
Linux, macOS, iOS and Andriod.
12
Applications Of C#
❖ Gaming applications
❖ Web applications
❖ Mobile applications for pocket PCs, PDAs, and cell phones
❖ Web services
❖ Cloud applications
❖ Simple standalone desktop applications such as Library Management Systems, Student Mark
Sheet generation, and so on
❖ Large-scale enterprise applications
❖ Complex distributed applications that can spread over a number of cities or countries
13
.Net Framework
❖ .NET is a programming framework created by Microsoft that developers can use to create
applications more easily.
❖ The first beta version released in 2000 and first version of the .Net framework was released in
the year 2002
❖ A framework is just a bunch of code that the programmer can call without having to write it
explicitly.
❖ It provides a controlled programming environment where software can be developed, installed
and executed on Windows-based operating systems.
❖ It is basically a collection of libraries.
14
.Net Framework
❖ Is a programming platform that is used for developing Windows, Web-based, and mobile software.
❖ It has a number of pre-coded solutions that manage the execution of programs written specifically for
the framework.
❖ A programmer can develop applications using one of the languages
(C#.NET,VB.NET,C++.NET,J#.NET,F#.NET,JSCRIPT.NET,WINDOWS POWERSHELL,IRON RUBY, IRON
PYTHON,C OMEGA,ASML(Abstract State Machine Language)) supported by .NET.
❖ The .NET Framework is an infrastructure that is used to build, deploy, and run different types of
applications and services using .NET technologies.
❖ The .NET Framework is an infrastructure that is used to Minimize software development, deployment,
and versioning conflicts.
15
.NET Architecture
16
.NET Architecture
17
.NET Architecture - Language
❖ The types of applications that can be built in the .NET framework is classified broadly into the
following categories :
➢ WinForms: This is used for developing Forms-based applications, which would run on an end user machine
➢ ASP.NET: This is used for developing web-based applications, which are made to run on any browser such
as Internet Explorer, Chrome or Firefox. (Active Server Page)
➢ ADO.NET: This technology is used to develop applications to interact with Databases such as Oracle or
Microsoft SQL Server (ActiveX Data Object)
18
.NET Architecture - Library
❖ A class library is a collection of methods and functions that can be used for the core purpose.
❖ e.g. - class library with methods to handle all file-level operations. So there is a method which
can be used to read the text from a file. Similarly, there is a method to write text to a file.
19
.NET Architecture - Library
20
Common Language Runtime (CLR)
21
Common Language Runtime (CLR)
22
Common Language Runtime (CLR)
23
Architecture of CLR
24
Main components of CLR
25
Main components of CLR
❖ Common Language Specification (CLS) : It is responsible for converting the different .NET
programming language syntactical rules and regulations into CLR understandable format.
Basically, it provides the Language Interoperability.
❖ Common Type System (CTS) :Every programming language has its own data type system, so CTS
is responsible for understanding all the data type of system.
❖ Garbage Collection (GC): It is used to provide the Automatic Memory Management feature.
❖ Just In – Time Compiler (JIT) : It is responsible for converting the CIL(Common Intermediate
Language) into machine code or native code using the Common Language Runtime environment.
26
Download and Install .NET Framework
or
1. Download .Net Framework from .NET Framework , choose developer pack/runtime pack and
install it in your system.
27
Download and Install .NET Framework
28
Download and Install .NET Framework
29
Download and Install .NET Framework
30
Download and Install .NET Framework
31
Download and Install .NET Framework
32
Example - write and compile source code
33
Example - write and compile source code
3. Go to your file directory where you save your HelloWorld.cs source file.
4. And type following example source code and save the file with HelloWorld.cs extension.
34
Example - write and compile source code
35
Example - write and compile source code
36
37
Happy Coding !!!
38