0% found this document useful (0 votes)
53 views

Module-1 With Content

This document provides an overview of .NET Framework and C# programming. It discusses the limitations of previous technologies like C/Win32 and Visual Basic 6.0 that .NET aimed to improve on. It then covers the key benefits of .NET Framework like consistent programming model, cross-platform support, language interoperability, and automatic resource management. The architecture of .NET Framework 4.0 is explained, with components like the Common Language Runtime (CLR) and Common Type System (CTS). Finally, it describes the .NET execution process where source code is compiled to assemblies that are executed by the CLR.

Uploaded by

Pronab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Module-1 With Content

This document provides an overview of .NET Framework and C# programming. It discusses the limitations of previous technologies like C/Win32 and Visual Basic 6.0 that .NET aimed to improve on. It then covers the key benefits of .NET Framework like consistent programming model, cross-platform support, language interoperability, and automatic resource management. The architecture of .NET Framework 4.0 is explained, with components like the Common Language Runtime (CLR) and Common Type System (CTS). Finally, it describes the .NET execution process where source code is compiled to assemblies that are executed by the CLR.

Uploaded by

Pronab
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Programming using C# .

NET [20MCA42]
Module – 1:
Chapter – 1: Getting started with .NET Framework 4.0
1.1 C# Understanding Previous Technologies
1.2 Components of .NET Framework 4.0
1.3 Benefits of .NET Framework
1.4 Architecture of .NET Framework 4.0
1.5 .NET Execution Engine CLR
1.6 CTS
1.7 Metadata and Assemblies
1.8 .NET Framework Class Library
1.9 Windows Forms
1.10 ASP .NET and ASP .NET AJAX
1.11 ADO .NET,
1.12 Windows workflow Foundation
1.13 Windows Presentation Foundation,
1.14 Windows Communication Foundation,
1.15 Widows CardSpace
1.16 LINQ
Chapter - 2: Introducing C#
2.1 Creating a Simple C# Console Application
2.2 Identifiers and Keywords
2.3 System Data Types
2.4 Variables and Constants
2.5 Value Types
2.6 Reference Types
2.7 Understanding Type Conversions
2.8 Boxing and UnBoxing
2.9 Namespaces
2.10 The System namespace
2.11 .NET ArrayTypes

Prepared by
Mrs. Suma M G
Assistant Professor
Department of MCA
RNSIT
Bengaluru – 98.
Module – 1 20MCA42

Chapter - 1

Getting started with .NET Framework 4.0 and C#


Introduction:
.NET Framework is an essential component of the Windows operating system, which helps in creating
applications by integrating different programming languages, such as C#, Visual Basic, J#, and Visual C++.
This framework consists of a virtual execution system called the Common Language Runtime (CLR) and a set
of class libraries. CLR is a Microsoft product of the common creating execution and development environments
in which languages and libraries work together.

Evolution of .NET:-
At the time of mid ninety, java was so popular to develop the application because of its platform independent
technique and open source policy of Sun Microsystems. Around 2002, Sun Microsystems introduced the Java
2 Enterprise Edition (J2EE) to create the distributed application.
As the J2EE was gaining popularity, the market share of Microsoft ultimately led to the turn down. Therefore,
Microsoft starts working on a project known as Next Generation Windows Services (NGWS) to recover the
market share. The project took around three years to build up, which is now known as .NET. Microsoft released
the different version of .Net with the different name as listed below:

1.1 Understanding Previous Technologies:


Let’s begin with a brief discussion on limitations of the previous state of affairs.
a) C/Win32 Language:
Disadvantages:
i. Concept of Pointers is the powerful feature. But, they are highly insecure and makes it vulnerable.
ii. The concept of reusability is achieved only through functions, so it makes more complex for coding big
projects and hence lot of time is wasted.
iii. C developers have to concentrate on memory management as there is no automatic Memory
management.
iv. Since C is structured language, it lacks all the benefit of object oriented programming
v. C doesn't perform Run Time Type Checking. It only does compile time type checking.
Besides all these, C is a powerful language, that’s why, a majority of Operating Systems are built using C.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 1 | 29


Module – 1 20MCA42
b) C++/MFC Language:
Advantages:
 Stronger type checking
 Support for data abstraction, object-oriented programming and generic programming
Drawbacks:
 Not truly object oriented
 Not suitable for developing web technologies
 It does not support versioning i.e., creation and management of multiple versions of Software.
 It is not type-safe. It means the following
 Arrays are unbound.
 Compile time errors are not generated when uninitialized arrays are used
 It still support pointers which will leads to major errors in programs and also it makes highly
insecure

c) Visual Basic 6.0:


Advantages:
 VB was originally designed as a programming language for non-programmers. To that end, the
syntax was designed to read more like natural language sentences than instructions to a computer.
 There is no need to specify the type of a variable, or even declaring the variable itself.

Drawbacks of VB are:
 VB is not fully object oriented
 Developing multi-threading applications using VB is a bit complex as we have to call the low level
WIN32 API calls.
 No need to declare the data type of variables prior to its usage, there will be more chances to get
runtime errors.

d) JAVA / J2EE:
Advantages:
i. Platform Independent
ii. It contains large number of pre-defined packages that contain various type definitions.
iii. Java programmer can build pure Java applications complete with database connectivity, messaging
support, web-enabled front ends, and a richer user interface.
iv. Java eliminates pointers which is major concern in C and C++
v. Garbage collection is one of the powerful features, which automatically cleans the memory.
Disadvantages:
i. Java is a very elegant language that means must use of Java front-to-back during development cycle
ii. Java applets are not supported by all the browsers and they need separate plug-in to be installed
iii. Java developers have less control over on garbage collection to free objects
iv. Primary goal of Java is to make Java as a single programming language for every need. So Java offers
a little chance for language integration.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 2 | 29


Module – 1 20MCA42
1.2 Benefits of .NET Framework:
The following are the benefits of .NET Framework:

⚫ Consistent Programming Model: Provides a consistent object-oriented programming model across


different language. You can use this model to create programs for performing different tasks, such as
connecting to and retrieving data from databases, and reading and writing in files.

⚫ Cross-Platform Support: Specifies that any windows platform that supports CLR can execute .NET
application, that is, .NET application enables interoperability between multiple Windows operating
systems.

⚫ Language Interoperability: Enables code written in different languages to interact with each other.
This allows reusability of code and improves the efficiency of the development process.

⚫ Automatic Management of Resource: In .NET, no need to manually free the application resources,
such as files, memory, network, and database connection because .NET Framework provides a feature
called CLR that automatically tracks the resource usage and helps you in performing the task of manual
resource management.

⚫ Ease of Deployment: In most cases, to install an application, you need to copy the application along
with its components on the target computer. But in .NET, applications are deployed in the form of
assemblies that’s why, do not affect the existing applications. Therefore, registry entries are not required
to store information about applications and also version problem is eliminated in .NET Framework.

1.3 Architecture of .NET Framework 4.0:


The latest version of .NET framework provides:
• In developing portable, scalable, and robust applications.
• Developed applications can be executed in a distributed environment.
Therefore, you can say that the .NET Framework 4.0 is designed to address the latest needs of the developers.
The architecture of .NET
Framework 4.0 mainly consists of
components of .NET Framework
2.0 and 3.0 with few enhancement
as shown in figure 1.1.

Figure 1.1: .NET Execution Engine

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 3 | 29


Module – 1 20MCA42
1.4 .NET Execution Engine:
The following figure summarizes the workflow between a .NET source code, a .NET compiler, and the .NET
execution engine:

The .NET execution process completes as given


below:
i. When you compile source code by selecting
.NET aware compilers such as Visual Basic, C#,
Visual C++, J#, or any of the third party
compilers, such as COBOL, Perl or Eiffel.
ii. The .Net aware compiler converts source code in
to binaries that are called as assemblies. The
assembly can be either *.dll or *.exe depending
on the entry point defined in the application.
iii. Assembly contains IL code, Metadata and
Manifest data.
NOTE: IL(Intermediate Language) code is also
known as MSIL(Microsoft IL) / CIL(Common IL)
has a machine-readable instruction sets.
iv. The next level of compilation happen just before
the application is executed. At this point, if loader
Figure 1.2: .NET Execution Engine detects an IL code it loads mscoree.dll which
denotes Runtime Execution Engine(CLR).
v. Then loaded IL code must be converted to Platform-specific code by a Just-in-Time(JIT) compiler at
runtime.
vi. Base class Library (mscorlib.dll): This library encapsulates various primitives such as file IO, Data
Access, Threading, XML/SOAP etc. When building .NET binaries you always make use of this
particular assembly.

1.5 Components of .NET Framework 4.0:


The .NET Framework provides all the necessary components to develop and run an application. The
components of .NET Framework 4.0 architecture are as follows:

• Common Language Runtime (CLR) • ADO.NET


• Common Type System (CTS) • Windows Workflow Foundation
• Metadata and Assemblies • Windows Presentation Foundation
• .NET Framework class library • Windows Communication Foundation
• Windows Forms • Windows CardSpace
• ASP.NET and ASP.NET AJAX • LINQ
Let’s now discuss about each of them in detail.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 4 | 29


Module – 1 20MCA42
1.6 CLR[Common Language Runtime]:
“CLR is an Execution Engine for .NET Framework applications”.
CLR is a heart of the.NET Framework. It provides a run-time environment to run the code and various services
to develop the application easily.
The services provided by CLR are –
 Memory Management  Thread execution  Code safety
 Exception Handling  Code execution  Verification
 Debugging  Language Integration  Compilation
 Security

The following figure shows the process of compilation and execution of the code by the JIT Compiler:

i. When you compile your source code


by selecting .NET aware compilers;
that compiler converts source code in
to bytecode known as IL / MSIL /
CIL. This code is referred to as
Assembly.

ii. After compiling, the code is passed


to the CLR at the runtime; which may
take some action.

iii. CLR uses the rules to examine the


code which are stated in the CLS and
Figure 1.3: Compilation and execution by the JIT CTS.
iv. After verifying, a JIT [Just-In-Time] compiler extracts the metadata from the file to translate that verified
IL code into CPU-specific code or native code. These type of IL Code is called as managed code.
v. The source code which is directly compiles to the machine code and runs on the machine where it has been
compiled such a code called as unmanaged code. It does not have any services of CLR.
vi. Automatic garbage collection, exception handling, and memory management are also the responsibility of
the CLR.
Let’s now explore the managed code, unmanaged code, and memory management in CLR.

Managed Code: Managed code is the code that is executed directly by the CLR. The application that are created
using managed code automatically have CLR services, such as type checking, security, and automatic garbage
collection.
The process of executing a piece of managed code is as follows:
 Selecting a language compiler
 Compiling the code to IL[This intermediate language is called managed code]
 Compiling IL to native code
 Executing the code
Suma M G, Asst. Prof, Dept. of MCA, RNSIT 5 | 29
Module – 1 20MCA42
Unmanaged Code: Unmanaged Code directly compiles to the machine code and runs on the machine where it
has been compiled. It does not have services, such as security or memory management, which are provided by
the runtime. If your code is not security-prone, it can be directly interpreted by any user, which can prove
harmful.

Automatic Memory Management: CLR calls various predefined functions of .NET framework to allocate and
de-allocate memory of .NET objects. So that, developers need not to write code to explicitly allocate and
de-allocate memory.

1.7 CTS [Common Type Specifications]:


The CTS defines the rules for declaring, using, and managing types at runtime. It is an integral part of the
runtime for supporting cross-language communication.
The common type system performs the following functions:
⚫ Enables cross-language integration, type safety, and high-performance code execution.
⚫ Provides an object-oriented model for implementation of many programming languages.
⚫ Defines rules that every language must follow which runs under .NET framework like C#, VB.NET, F#
etc. can interact with each other.
The CTS can be classified into two data types, are
i. Value Types
ii. Reference Types

Figure 1.4: Hierarchy of value type and reference

The base class of all the types is the System.Object class. The hierarchy of the types as shown figure 1.4:
The following table shows some of the differences between values types and reference types.

Value Types Reference Types


Allocated on stack Allocated on heap
variable contains the address of memory location where
variable contains the data itself
data is actually stored
When copying a reference type variable to another
When we copy a value type variable to
variable, only the memory address is copied. Both
another one, the actual data is copied and
variables will still point to the same memory location,
each variable can be independently
which means, if we change one variable, the value will be
manipulated.
changed for the other variable too.
Integer, float, boolean, double etc are value
string and object are reference types.
types.
Derived from System.ValueType Derived from System.Object

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 6 | 29


Module – 1 20MCA42
1.8 Metadata and Assemblies:
A metadata is binary information that describes your program, stored in a CLR Portable Executable (PE) file
or the memory.
The metadata contains the following:
 Assembly information, which includes the metadata identity that can be name, version, culture,
public key, the types of assemblies, other reference assemblies, and security permissions.
 Information about types, such as name, visibility, base class, interfaces used, and members
(methods, fields, properties, events, and nested types)
 Attribute information that modifies the types and members of a class.
An assembly contains a self-describing binary file that can be either Dynamic Link Library (DLL) or
Executable (EXE). It also contains a collection of types, such as classes, interfaces and structures.
There are two types of assembly:
i. Single file assembly: Single assembly can contain multiple code files of single code file can have more
than one assembly.
It contains the type information and
implementation as well as the
assembly’s manifest into a single
physical file.
Example: Class Libraries, Windows
Forms / WPF applications, Console
applications and Windows Services.
Figure 1.5: Structure of Single-File Assembly

ii. Multi-file assembly: An assembly can


consist of one or more files called modules.
Exactly one of these modules contains the
assembly manifest.
The most common reason for multi-file
assemblies is when a single assembly
combines code from multiple programming
languages.

Figure 1.6: Structure for Multi-file Assembly


Assemblies can stored in two types:
Static assemblies: Static assemblies include interfaces, classes and resources. These assemblies are stored in
PE (Portable executable) files on a disk.
Dynamic assemblies: Dynamic assemblies run directly from the memory without being saved to disk before
execution. However, after execution you can save the dynamic assemblies on the disk.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 7 | 29


Module – 1 20MCA42
Assembly Content:
Assembly is a logical unit that consists of 4 elements as follows:
⚫ Manifest: The manifest, also known as assembly manifest,
contains the assembly metadata needed for providing the
assembly’s version requirements and security identity.
⚫ Metadata
⚫ IL code(static or dynamic)
⚫ Set of resources[bitmaps, jpeg]
The list of information stored in the assembly manifest are listed below:
Table1.1: Information stored in the assembly manifest
Information Description
Assembly name Specifies the name of the assembly
Indicates a major version number, a minor version number, and a revision and build
Version number
number. The CLR uses these numbers to enforce the version policy.
Culture Provides information about the culture or language that the assembly supports.
Strong name Indicates a public key from the publisher if the assembly contains a strong name
information
Contains the information required to map a type reference to the file that contains its
Type reference declaration and implementation. Types exported from the assembly use the type
information
reference information.
Information on Provides the list of assemblies, which are used as a reference by the assembly. The
referenced reference of assembly contains the whole details of dependent assembly, such as name,
assemblies assembly metadata and public key, if the assembly is strong named.

Global Assembly Cache:


The Global Assembly Cache (GAC) is a folder in Windows directory to store the .NET assemblies that are
specifically designated to be shared by all applications executed on a system.
 The assemblies must be sharable by registering them in the GAC, only when needed; otherwise, they
must be kept private.
 Each assembly is accessed globally without any conflict by identifying its name, version, architecture,
culture and public key.
You can deploy an assembly in GAC by using any one of the following:
⚫ An installer that is designed to work with the GAC
⚫ The GAC tool known as Gacutil.exe
⚫ The Windows Explorer to drag assemblies into the cache.

Strong Name Assembly:


A Strong Name contains the assembly’s identity, that is, the information about the assembly’s name, version
number, architecture, culture and public key.
⚫ Using Microsoft Visual Studio .NET and other tools, you can provide a strong name to an assembly.
⚫ By providing strong names to the assembly, you can ensure that assembly is globally unique.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 8 | 29


Module – 1 20MCA42
Benefits:
⚫ Provides uniqueness to the names by generating a private key.
⚫ Ensures that a version of the assembly you are using comes from the same publisher that created the
version the application was built with
⚫ Facilitates integrity check, which ensures that the contents of the assembly do not change since its last
build.

Private and Shared Assembly:


A single application uses an assembly, then it is called as a private assembly.
Example: If you have created a DLL assembly containing information about your business logic, then the DLL
can be used by your client application only. Therefore, to run the application, the DLL must be included in the
same folder in which the client application has been installed. This makes the assembly private to your
application.
Assemblies that are placed in the Global Assembly cache so that they can be used by multiple applications, then
it is called as a shared assembly.
Example: Suppose the DLL needs to be reused in different applications. In this scenario, instead of downloading
a copy of the DLL to each and every client application, the DLL can be placed in the global assembly cache by
using the Gacutil.exe tool, from where the application can be accessed by any client application.

Side-by-Side Execution Assembly:


The process of executing multiple versions of an application or an assembly is known as side-by-side
execution. Support for side-by-side storage and execution of different versions of the same assembly is an
integral part of creating a strong name for an assembly.
⚫ Strong naming of .NET assembly is used to provide unique assembly identity by using the sn.exe
command utility.
⚫ The strong-named assembly’s version number is a part of its identity, the runtime can store multiple
versions of the same assembly in the GAC.
⚫ Load these assemblies at runtime.

1.9 .NET Framework Class Library:


The .NET Framework helps in speeding up the application development process and provide access to system
functionality.
To facilitate interoperability between languages, most .NET Framework types are CLS-compliant and can be
used from any programming language whose compiler conforms to the common language specification (CLS).
The .NET Framework types are the foundation on which .NET applications, components, and controls are built.
These entities perform the following functions:

• Represent base data types and • Access information about loaded types
exceptions • Invoke .NET Framework security checks
• Encapsulate data structures • Provide data access, rich client-side GUI, and
• Perform I/O server-controlled, client-side GUI

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 9 | 29


Module – 1 20MCA42
The .NET Framework Class Library (FCL) is a library consisting of namespaces, classes, interfaces, and
data types included in the .NET Framework.
This library is organized into namespaces that contain functionally related groups of classes. These namespaces
are divided among different categories, such as data access, common types, debugging, file access, network
communication, security, Windows & Web applications, Web services, XML data etc.
The following points need to be remembered while using the FCL:
• The classes, interfaces, structures, and enumerated values are collectively referred to as types.
• The different types in the framework are arranged in a hierarchy of namespaces. Namespaces are
arranged a hierarchy that has words separated by Dots (●).
Example: System.IO.Stream, System.Windows.Forms.Form respectively
• The System namespace is a parent of all the types available in the .NET Framework Class Library.
Example: System namespace contains base data type’s classes, such as Object, Int, Array, and Short.
• All types must have a base class. The exception to this rule is the System.Object type, which acts as the
base type for all types in .NET Framework. This implies the compiler explicitly declares its base class
to the Object class.

1.10 Windows Forms (WF):


Windows forms is the graphical representation of any window displayed in an application.
 It is included as a part of Microsoft’s .NET Framework.
 Create an application using Window Forms in any CLR supported language.
 Used to either accept input from or display information to the user.
 Add controls to the forms and raise events, such as mouse-click, which is handled by event handlers in
an application.

1.11 ASP .NET and ASP .NET AJAX:


ASP.NET is a web development mode, which is used to deliver interactive and data-driven web application
over the internet. It also consists of a large number of controls, such as text boxes, buttons, and labels for
assembling, configuring, and manipulating code to create Hyper Text Markup Language (HTML).
Advantages of ASP.NET:
• Better Performance: Specifies that when you request a web page for the first time after compiling
ASP.NET code, the CLR compiles the code and stores the cached copy of the result. Now, for any
subsequent calls to the same page, the cached copy of the result is retrieved instead of going back to the
server.
• Improved Security: Refers to the different methods of authentication included in ASP.NET:
 Forms: Allows the ASP.NET application to use its own custom business logic for authentication.
 Windows: Checks the identity of a user against the Windows user accounts that are stored on
the Web Server. If the credentials of a user match with that of a Windows user account, then the
user is authenticated.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 10 | 29


Module – 1 20MCA42
• Greater Scalability: Specifies that the session states in ASP.NET are maintained in a separate process on
a different machine or database. This enables cross-server sessions to occur, solving the problem of web
forms when more web servers need to be added as the traffic grows.
• Cookie-less Sessions: Specifies that ASP.NET stores the session even when the cookies in a Web browser
are disabled. In such a case, the session ID is passed as a part of the Uniforms Resource Locator (URL).

AJAX, which is also known as Atlas, is used as an extension for ASP.NET to develop and implement the
AJAX functionality. ASP.NET AJAX has both side client and server components to develop the Web
applications, which can update the information on a Web application without reloading the page completely.
Advantages of using AJAX:
• Asynchronous: Enables asynchronous calls to the Web server without making the users wait for the data.
• Minimal transfer of data: Helps in sending only a part of the modified data to the web server to minimize
the network traffic and perform the operations quicker.
• Minimal processing on the Web server: Minimizes the processing on the Web server as only the
necessary data needs to be sent. Now, the server is not required to send a full page back to the user.
• Context: Reduces burden on the server by sending a request back to the server through the client-side
script. AJAX-based applications implement partial page post backs instead of full page post backs, which
reduce the data traffic between the client and server.

1.12 ADO .NET:


ADO.NET is a technology used for working with data and databases of all types.
It provides access to data sources, such as Microsoft SQL Server, data sources exposed through OLE DB, and
Extensible Markup Language (XML).
Advantages:
• Disconnected Data Architecture: Implies that applications connect to the database only when data
needs to be retrieved or modified. After the database operation has been performed, the connection to
the database is closed. To perform any database operation again, the connection with the database will
have to be re-established.
• Cached Data in Datasets: Follows a disconnected architecture for accessing or modifying data. The
data is accessed and later stored in the datasets. A dataset is a cached set of database records, which is
independent of data source. Even when you are disconnected from the database on which you are
working, you can make modifications in the database.
• Scalability: Reduces the traffic on the database and saves the resources to make the database more
efficient. ADO.NET help in attaining scalability by performing all database operations on the dataset
instead of on the database.
• Transfer of Data in XML Format: Transfers data from a database into a dataset and from the dataset
to another components using XML, which is the standard format used for transferring data in ADO.NET.
• Interaction with the Database through Data Commands: All operations on database are performed,
such as retrieving, modifying, or updating of data using data commands. A data command is either a
Structured Query Language (SQL) statement or a stored procedure.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 11 | 29


Module – 1 20MCA42
1.13 Windows workflow Foundation(WF):
WF is a technology introduced by Microsoft, which provides a programming model for building workflow
based applications on Windows.
It includes activities, workflow runtime, workflow designer, and a rules engine. WF is a part of .NET
Framework 3.0, 3.5 and 4.0.
Feature
• Activities: Receives some parameters from the developer, execute the actions specified in the parameters,
and then the flow is transferred to the next activity.
• Workflow Designer: Designs workflows by placing activities within the workflow model. One interesting
feature is that it can be re-hosted within any Windows Forms application.
• Workflow Runtime: Executes the activities in a workflow. It is a lightweight and extensible engine that
resides within a .NET process, facilitating the developers to bring workflow to anything from a Windows
Forms application to an ASP.NET website or a Windows Service.
• Rules Engine: Enables declarative, rule-based development for workflows and any .NET application to be
used.
The architecture of WF is shown
in figure 1.7:
There are 3 layers:
i. Model Layer: The top layer
is model layer where the
developers build their code
to run in the workflow. This
layer provides the developer
to following activities:
• Add built-in activities
• Create Custom activities
• Building rules and Figure 1.7: Windows Workflow Foundation Architecture
workflows
ii. Runtime Layer: The second layer is runtime layer. It ensures that the processes, such as execution of rules,
tracking and scheduling and managing state lifecycle and activation, take place.
iii. Hosting Layer: The last layer is hosting layer, which connects the engine and the process that is being
executed. It also provides a set of services, such as persistence, timer, tracking, communication,
transactions, and threading, required for managing and controlling the workflow.

1.14 Windows Presentation Foundation(WPF):


WPF provides the base for building applications and a clear separation between the user interface and the
business logic. WPF helps in building interfaces that include documents, media, two or three dimensional
graphics, animations and web-like characteristics. The architecture of WPF shown below:
WPF provides document services, such as XML Paper Specification (XPS) documents and packaging services.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 12 | 29


Module – 1 20MCA42
• XPS documents are shown with an XML-based schema that defines the layout and visual appearance of
a page.
• The WPF namespace System.IO.Packaging helps in organizing data, content, and resources of your
application into a single, portable, easy to access, and distributable .zip document.
WPF aims at unifying several
user interface services, such as
application services, controls
layout, data-binding and
deployment services.
It provides shape for 2-D graphics
by providing in-built brushes,
pens, and geometries.
WPF supports various video
formats, such as WMV, MPEG,
and AVI files.
It also supports audio files, some
common image formats and
Figure 1.8: Architecture of WPF
animations.
WPF provides some basic services, such as accepting input and raising events, property system, and
accessibility.

1.15 Windows Communication Foundation (WCF):


WCF is one of the new technologies introduced by Microsoft in .NET Framework 3.0 for building and running
connected systems.
It is a service-oriented technology for developing applications in a distributed system that provides services to
the client applications.
The enhancements of WCF as compared to the previous technologies are as follows:
• Merges technologies, such as Web services, remoting, distributed transactions, and message queuing in
one place and reduces development time.
• Consists of many powerful enterprise features
• Integrates easily with other technologies and consequently, enables greater interoperability.
The WCF Architecture is composed of the following five layers:
i. Application: Represents the location of the application.
ii. Contracts: Consists of services, data and message contracts as well as bindings and policies. The
contracts layer gives you information about the different features of the message system [which
involves sending and receiving the messages from one end to another].
iii. Service Runtime: Gives information about the different behaviours that take place at runtime. This
layers loads all the services.
iv. Messaging: Gives information about different channels that are required at the time of processing a
message. This layer deals with the message content that needs to be communicated.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 13 | 29


Module – 1 20MCA42
v. Activation and Hosting: This layer deals any service can be hosted using the Internet Information
Services (IIS) or Windows Activation Service.

Figure 1.9: Architecture of WCF

1.16 Widows Card Space (WCS):


Windows CardSpace is a client software provided by Microsoft that improves the safety of accessing resources
and helps in sharing personal information on the internet. It helps programmers in developing websites and
software that are less prone to identity-related attacks, such as phishing.
Advantages:
• Reducing the problems of traditional online security mechanisms by relying on separate desktop and
cryptographically strong authentication rather than on user names and passwords.
• It facilitates secure online transactions, such as online shopping, banking, and bill payment.
You can create a card using the WCS utility that comes with .NET 4.0 as shown below:

WCS is based on the identity meta


system. This system allows you to use
different digital identities across different
platforms. There are two types of cards
available:
 Personal Cards: is based on the self-
issued identity providers
 Managed Cards: is based on identity
providers provided by vendors other
than Microsoft.
Figure 1.10: WCS User Interface

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 14 | 29


Module – 1 20MCA42
The overall process of CardSpace contains issuing, acquiring and using digital identifies that can be defined by
the following three distinct roles:
→ User – refers to an entity containing a digital identity.
→ Identity Provider – refers to a provider that provides a digital identity to the user. The digital identity
is used to provide information about the username and password of the user.
→ Relying Party – refers to an application that relies on a digital identity. It can use an identity to
authenticate a user and then make authorization decision, such as allowing or disallowing the user to
access information.

1.17 LINQ:
LINQ is an acronym for Language Integrated Query, which is one of the components of .NET Framework 4.0
that adds native data querying capabilities to .NET languages by using syntax similar to SQL.

The following are simple LINQ


Visual Basic
query in different language:
When you execute the preceding Dim query = From s In Students Where s.Gender = “M”
Select s.Name
query, it returns the names of all
the male students and is stored in C#
the variable query.
var query = from s in Student where s.Gender = “M”;
select s.Name;

To print that list, you have to write the following lines of code:

Visual Basic In this code, you can find that the syntax of the query is similar to

For Each name In query the SQL, which we normally follow for accessing relational data.
Response. Write(name) It is important to note that even if it looks similar to SQL, the LINQ
Next
query displayed is not an SQL statement. Instead, it is purely in C#
C# language.
foreach(var name in query){ LINQ queries resemble SQL, they are not restricted to accessing
Response.Write(name);
only relational databases. LINQ enabled data access components
} are as follows:

→ LINQ to ADO.NET:- Includes two options, LINQ to SQL, which translates a query into an SQL query,
and then issues it against the tables specified in the query in an SQL Server database, and LINQ to
DataSet, which executes a query on the contents of a DataSet.
→ LINQ to Object: - Allows querying objects in a collection. LINQ to Objects is not dynamic. After
creating and using the result set, any changes made to the source collection do not automatically update
the result set.
→ LINQ to XML: - Allows querying of XML data. In addition, it helps in creating and manipulating XML
data. This option has a different syntax; however, the basic LINQ query remains the same.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 15 | 29


Module – 1 20MCA42

Additional Topics:
CLS [Common Language Systems]:
The Common Language Specification (CLS) is a set of rules that a given .NET-aware compiler must support to
produce code that can be hosted by the CLR, while at the same time be accessed in a uniform manner by all
languages that target the .NET platform. In many ways, the CLS can be viewed as a subset of the full
functionality defined by the CTS.

The CLS helps enhance and ensure language interoperability by defining a set of features that developers can
rely on to be available in a wide variety of languages. The classes that follow the rules specified by CLS are
termed as CLS-complaint classes. The classes defined in the .NET Framework class library are CLS-Compliant.
The CLS describes a set of features that different languages have in common. CLS Compliance is especially
important when creating software components that will be used by other languages.

The most important rules, and which apply to public and protected members are
i. All types appearing in a method prototype must be CLS-compliant
ii. Array elements must have a CLS-compliant element type. Arrays must also be 0-indexed
A CLS compliant class must inherit from a CLS-compliant class only

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 16 | 29


Module – 1 20MCA42
Chapter - 2

Introducing C#
2.1 Creating a Simple C# Console Application:
A class declaration in C# is composed of attributes, modifiers, the class name, base class and interfaces, and a
body. Attributes, modifiers, and bases are all optional.
Example 2.1
 It is declared inside a class. It must be
using System;
static and it should not be public.
class HelloClass {
public static int Main(string[] args){  C# executable program must include
Console.WriteLine("Hello World!"); the Main() method in any one of the
Console.ReadLine(); classes.
return 0;
}  public: is an access modifier that tells
} the main method is accessible by
anyone.
 static: the Main method is a global one and can be called without creating an instance of the class.
 void: is a type modifier, that the Main method does not return any value.
 string[] args: method has single parameter which happens to be an array of strings and also contain any
number of incoming command – line – arguments.

Rules to use members:


 All the keywords are in the lowercase
ex: public, global, private and so on.
 All the namespaces, types and member names begin with an initial capital letter and have capitalized by
embedded words
Variation on the Main() method:
 The execution of C# program begins with Main method. In C#, we are having four overloaded forms of
Main method.

 When a program starts, it looks for an entry point. This is the role of the Main() method. In fact, a
program, that is an executable program, starts by, and stops with, the Main() method. They are...

i. public static void Main(string[] args) { -------} //No Return Type and String Arguments

ii. public static void Main() { ------- } //No Return Type and No Arguments

iii. public static int Main(string[] args) { - - - } //Integer Return Type & String Argument

iv. public static int Main() { ---------- } //Integer Return Type and No Arguments

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 17 | 29


Module – 1 20MCA42
2.2 Identifiers and Keywords:
An Identifiers is a sequence of character used to identify a variable, constant, or any user-defined programming
element.
Rules:
⚫ Starts with a letter or an underscore and ⚫ Must not be a reserved word
ends with a character. ⚫ Must be a complete word without any
⚫ Can have letters, digits and underscores blank spaces.
Example: sum, SUM, _sum

Keywords are the reserved words whose meanings are predefined to the C# compiler.
Rules:
⚫ You cannot use keywords as ⚫ If you want to use the keywords as identifiers,
variable, methods and properties prefix the keyword with @ character.
Table 2.1: Lists of Reserved keywords available in C#
Reserved Keywords
abstract as base bool break byte case this object
Catch char checked class const continue decimal is sizeof
Default delegate do double else enum event out readonly
Extern false finally fixed float for if param using
foreach goto int public protected private short namespace unchecked

2.3 System Data Types:


The C# language provides a rich set of built-in data types.
Points:
⚫ All variables, whether user-defined or built-in (intrinsic), can be used as objects anywhere in a program,
⚫ All variables in a program are automatically initialized to default values by the system when they are
declared.
C# variables are categorized in to three:
i. Value Types: which include all numerical data types, as well as enumerations and structures, are
allocated on the stack.
ii. Reference Types: which include reference of an objects, are allocated on the heap.
iii. Pointer Types: which holds the memory address of a variable.

The Value types and


Reference types in
C# are divided into
different categories
that as shown below:

Figure 2.1: Shows different types of value types and reference types

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 18 | 29


Module – 1 20MCA42
2.4 Variables and Constants:
Variable Constant
Memory location whose size depends on its data Are the fixed values assigned to a constant
type. variables.
The memory reserved for the variables of different Values remain unchanged throughout the
data types are different execution of the program.
Example : int i=10; Example : const float pie=3.14;

2.5 Value Types:


Allow you to store the data directly into the variable. They are derived from System.ValueType. The value
type and their content are stored at the same location memory. The default values of value types are stored on
stack.
Table 2.2: Lists the available Primitive types in C# 2010.
Type Represents Ranges Default
Bool A Boolean value True or False False
Byte 8-bit unsigned integer type 0 to 255 0
Char Single 16-bit Unicode character U +0000 to U +ffff '\0'
128-bit precise decimal values with 28-29 (-7.9 x 1028 to 7.9 x 1028) / 100 to
decimal 0.0M
significant digits(16 bytes) 28

64-bit double-precision floating point type(8 (+/-)5.0 x 10-324 to (+/-)1.7 x


double 0.0D
bytes) 10308
32-bit single-precision floating point type(4
float -3.4 x 1038 to + 3.4 x 1038 0.0F
bytes)
Int 32-bit signed integer type(4 bytes) -2,147,483,648 to 2,147,483,647 0
-9,223,372,036,854,775, 808 to
Long 64-bit signed integer type(8 bytes) 0L
9,223,372,036,854,775,807
sbyte 8-bit signed integer type -128 to 127 0
short 16-bit signed integer type(2 bytes) -32,768 to 32,767 0
Uint 32-bit unsigned integer type 0 to 4,294,967,295 0
ulong 64-bit unsigned integer type(8 bytes) 0 to 18,446,744,073,709,551,615 0
ushort 16-bit unsigned integer type 0 to 65,535 0
Int 32-bit signed integer type -2,147,483,648 to 2,147,483,647 0

Example 2.1:

using System;
namespace Class_Demos{
class TypeMaxMin{
static void Main(){
Console.WriteLine("System Minimum");
Console.WriteLine("MinValue of sbyte{0}", sbyte.MinValue);
Console.WriteLine("System Maximum");
Console.WriteLine("MaxValue of sbyte{0}", sbyte.MaxValue);
Console.ReadLine();
} } }

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 19 | 29


Module – 1 20MCA42
Struct Type:
Struct types are a special form of classes having the properties of value types. As you know that the value type
are stored on the stack, inherently the struct types are also stored on the stack.
You can create struct types by using the “struct” keyword. When you create a struct object and assign it to
variable, the variable holds the value of the struct object.
Syntax: [attributes] [modifiers] struct identifier [:interface]{ Body;}

 Can apply only public, private and internal access modifiers to a struct and member definition.
 Cannot use the protected and protected internal access modifiers in structs because structs are
implicitly sealed. This means that a struct cannot be a parent class of other classes.
The struct types are divided into the following 5 categories:
⚫ Integral Type: C# provides a set of basic data types which are known as integral types such as sbyte,
byte, short, ushort, int, uint, long, ulong & char
⚫ Floating-Point Type: It is divided into two types; they are, single and double floats.
🡆🡆 Single float holds – is similar to the float data type, hold values up to 10308.
🡆🡆 Double float holds – is similar to the double data type, hold values up to 10308.
⚫ Decimal Type: It is equivalent to a long integer
⚫ Boolean Type: true or false
⚫ Nullable Type: when dealing with databases or when a user does not want to assign a value to a variable
of any data type.

Enum Type:
Enumerations are the user-defined integer data types that are declared using the “enum” keyword. You can
define a set of named integral constants that can be assigned to a variable.
Example 2.2:
namespace Class_Demos{
enum Color { Red=1, Green, Yellow}
class EnumEx{
public static void Main(){
Console.WriteLine("Select\n1.Red\n2.Green\n3.Yellow");
int colopt =Int32.Parse(Console.ReadLine());
Color col=(Color)colopt;
switch (col) {
case Color.Red:
Console.WriteLine("The selected color is RED");
break;
case Color.Green:
Console.WriteLine("The selected color is Green");
break;
case Color.Yellow:
Console.WriteLine("The selected color is Yellow");
break;
}
} } }

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 20 | 29


Module – 1 20MCA42
2.6 Reference Types:
C# also provides types that are passed by references to calling functions, known as reference types. Variables
that refer to the objects store the reference of the actual data. The reference types use heap to store the references
instead of the actual data.
Reference types can be categorized into 2 parts:
i. Pre-defined reference types: ii. User-defined reference types:
Dynamic type, Object type, String type Classes, Interfaces, Delegates, Arrays

Pre-defined reference types:


C# provides you some built-in reference types, which are as follows:
⚫ Dynamic type ⚫ Object type ⚫ String type

Dynamic type:
You can store any type of value in the dynamic type variable. It performs the type checking of the dynamic type
variable at run time.
Syntax: dynamic dyn=10;

Object type:
You can assign values of any type to the variable of object type. It performs the type checking of the variable
of object type at compile time.
Object type is base class for the other types such as value types, reference types, predefined types, user-defined
types. The object type can be assigned a value of any other types, but requires the type conversion.
⚫ A value type converted to the object type, the Example:
process is known as boxing int i=100
⚫ An object type converted to the value type, the object obj = i; // this is boxing
process is known as unboxing. int j=obj; //this is unboxing

String type:
It enables you to assign string values to the variables of string type. The string type is an alias for the
System.String class. String type is directly derived from the object type. You cannot change its value.
The value for a string type can be assigned using the string literals in 2 forms: quoted and @quoted.
Example: Where, @- Verbatim string literals: String
string sname = “C# 2010”; literals are embed escape characters
@“C:\Windows\Microsoft.NET\Framework”

Example 2.3: class StringEx{


public static void Main(){
string str="C# 2010";
Console.WriteLine("The variable value of str:" +str);
string str1=@"C:\Windows\Microsoft.NET\Framework";
Console.WriteLine("The variable value of str:" +str1);
Console.WriteLine("New string" +str.Replace('C','J'));
} }

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 21 | 29


Module – 1 20MCA42
User-defined reference types:
C# provides you some user-defined reference types, which are as follows:
• Classes • Interfaces • Delegates • Arrays

Classes:
All classes are user-defined data types and are considered as objects. class class_name{
All objects are derived from a single base class, known as static void Main(){
System.Object. - - - - -
}
}
Interface:
Interface define a set of functionalities that can be related to any class or struct. You cannot instantiate an object
through an interface. Interface have method declarations, these are known as abstract ie, they do not have
interface interface_name{ implementation part.
Abstract method delcarations(); A class that implements all the methods which is
- - - - - - - - declared in the interface; otherwise, the compiler
}
raise an error.

Delegates:
A delegates is almost equivalent to function pointer in C++ or C. C# contains two kinds of objects – those that
create a change and respond to the change.
A delegate acts as the tunnel between the two kinds of objects:
• Moving information from one side to another
• C# delegates are class methods and can be either static or instance class methods.
A delegate can keep a track of its own state by maintaining information in the object to which it belongs. You
can create a delegate by using delegate keyword, as shown below:
public delegate int Intdelegate(int i);
Example 2.4
namespace Class_Demos{
public delegate int intDelgate(int a);
class Calulator {
public static int SquareNum(int num){
return num * num;
}
}
class DelegatEx{
public static void Main(){
Console.WriteLine("Demonstrating Simple Delegate");
intDelgate obj = new intDelgate(Calulator.SquareNum);
Console.WriteLine("Value" + obj(2));
Console.Read();
} } }

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 22 | 29


Module – 1 20MCA42
Arrays:
An array is used to store the number of elements or variables of the same data type at contiguous memory
locations in an ordered manner.
int x[10]; //create a static array of 10 elements
Array cannot be created on the
int[] x=new int[10];
stack, but on the heap. This means
int multiX[ , ] = new int[5,5];//create an array of 5*5
you cannot create an array
statically in a method.
Length Property: This property returns the total number of elements in an array.
Example: int[ , ] a = new int[5,5];
Console.WriteLine(“Total no. of element:” +a.Length);//25
This is certainly useful because of this, you know the total size of the array, but determining the lower and upper
bounds of an array is difficult. For this reasons, C# provides two other methods of the array class:
GetLowerBound() and GetUpperBound().

NOTE: For all the data types, the base class is System.Object class.

Figure 2.2: Pictorial representation of all the data types

The following are the differences between pointer type and reference type:
Both, pointer and references represent memory address but the difference is that,
⚫ References are tracked by the garbage collector and pointer are not.
⚫ You can perform arithmetic operations on pointers but not on references

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 23 | 29


Module – 1 20MCA42
2.7 Understanding Type Conversions:
While writing C# applications, you often need to perform a typical task; that is to convert one data type to
another. For this type of conversion, type casting is used. Type casting has two forms:
 Implicit  Explicit
Implicit Conversion:
Implicit conversions are the conversions Example:
that are performed by the compiler, in a int i=123;
type-safe manner. float f=i; //Converting an integer to a float implicitly

Table 2.3: List of Conversion methods

Method Description
ToBoolean Converts types to a Boolean value, where possible
ToByte Converts a type to a byte.
ToChar Converts a type to a single Unicode character, where possible.
ToDateTime Converts a type (integer or string type) to date-time structures.
ToDecimal Converts a floating point or integer type to a decimal type.
ToDouble Converts a type to a double type.
ToInt16 Converts a type to a 16-bit integer.
ToInt32 Converts a type to a 32-bit integer.
ToInt64 Converts a type to a 64-bit integer.
ToSbyte Converts a type to a signed byte type.
ToSingle Converts a type to a small floating point number.
ToString Converts a type to a string.
ToType Converts a type to a specified type.
ToUInt16 Converts a type to an unsigned int type.
ToUInt32 Converts a type to an unsigned long type.
ToUInt64 Converts a type to an unsigned big integer.

Example 2.5:
using System;
namespace Class_Demos{
class StringEx1{
public static void Main() {
int i = 75;
string str = "12";
Console.WriteLine(i.ToString());
Console.WriteLine(Convert.ToInt32(str));
Console.Read();
} } }

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 24 | 29


Module – 1 20MCA42
Table 2.4: Lists of implicit conversions follows

From To
sbyte short, int, long, float, double , decimal
byte short, ushort, int, uint, long, ulong, float, double , decimal
short int, long, float, double , decimal
ushort int, uint, long, ulong, float, double , decimal
int long, float, double , decimal
uint long, ulong, float, double , decimal
long float, double , decimal
char ushort, int, uint, long, ulong, float, double , decimal
float double
ulong float, double , decimal

Explicit Conversion:
When one data type is converted Example:
explicitly to another data type, with float i=123.45f;//explicitly from floating-point to integer
the help or pre-defined functions. int x=(int)i;

C# allows to convert explicitly from type to another type ie, listed below:
Table 2.5: Lists of Explicitly conversion
From To
sbyte byte, ushort, uint, ulong, or char
byte sbyte, char
short sbyte,byte, ushort, uint, ulong, char
ushort sbyte, byte, short, char
int sbyte, byte, short, ushort, uint, ulong, char
uint sbyte, byte, short, ushort, uint, ulong, char
long sbyte, byte, short, ushort, uint, ulong, char
ulong sbyte, byte, short, ushort, uint, ulong, char
char sbyte, byte, or short
float sbyte, byte, short, ushort, int, uint, long, ulong, char, decimal
double sbyte, byte, short, ushort, int, uint, long, ulong, char, float, decimal
decimal sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double

class StringEx2{
Example 2.6: public static void Main(){
double d = 55673.745;
int i;
i = (int)d;
Console.WriteLine(i);
Console.Read();
} }

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 25 | 29


Module – 1 20MCA42
2.8 Boxing and UnBoxing:
Refer Page No: 21
Give LAB Program as example

2.9 Namespaces:
A namespaces is wrapper that is wrapped around one or more structural elements to make them unique and
differentiated from other elements.
 To declare namespace in C# .Net has a reserved keyword namespace XYZ{
“namespace”. class class_name{
- - - - - -
 If a new project is created in Visual Studio .NET it
}
automatically adds some global namespaces. }
 These namespaces can be different in different projects.
But each of them should be placed under the base namespace “System”.
 All namespaces should import by using keyword, which can tell the compiler which namespaces and
libraries of the code you want to use in the system.

Example 2.7: using System;


namespace Program{
public Class MyApp {
public static void Main() {
Console.WriteLine("Hello World");
}
}
}

2.10 The System namespace:


Within System we can find numerous useful types dealing with built in data, mathematical computations,
random number generation, environment variables, and garbage collection, as well as a number of commonly
used exceptions and attributes. So System is a root namespace.
The following are some of the common namespaces provided by the .NET Framework class library:
Table 2.6: Lists of common pre-defined namespaces in .NET Framework

Namespaces Meaning
These namespaces define a number of stock container objects
System.Collections (ArrayList, Queue, and so forth), as well as base types and interfaces
System.Collections.Generic that allow you to build customized collections. As of .NET 2.0, the
collection types have been extended with generic capabilities
System.Data System.Data.Odbc These namespaces are used for interacting with databases using
System.Data.OracleClient ADO.NET.
System.Data.OleDb
System.Data.SqlClient
Here, you find numerous types that can be used to programmatically
System.Diagnostics
debug and trace your source code.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 26 | 29


Module – 1 20MCA42
System.Drawing
Here, you find numerous types wrapping graphical primitives such
System.Drawing.Drawing2D
as bitmaps, fonts, and icons, as well as printing capabilities.
System.Drawing.Printing
System.IO Include file I/O, buffering, and so forth. As of .NET 2.0, the IO
System.IO.Compression namespaces now include support compression and port
System.IO.Ports manipulation.
Contains types related to network programming (requests/responses,
System.Net
sockets, end points, and so on).
System.Reflection Define types that support runtime type discovery as well as dynamic
System.Reflection.Emit creation of types.
Provides facilities to allow .NET types to interact with “unmanaged
System.Runtime.InteropServices
code” (e.g., C-based DLLs and COM servers) and vice versa.
Defines types used to build solutions that incorporate the .NET
System.Runtime.Remoting
remoting layer.
Security is an integrated aspect of the .NET universe. In the security-
System.Security centric namespaces you find numerous types dealing with
permissions, cryptography, and so on.
System.Threading This namespace defines types used to build multithreaded
applications.
A number of namespaces are specifically geared toward the
System.Web
development of .NET web applications, including ASP.NET and
System.Web.Security
XML web services.
Contains types that facilitate the construction of traditional desktop
System.Windows.Forms
GUI applications.
The XML-centric namespaces contain numerous types used to
System.Xml
interact with XML data.
Includes classes that allow you to use Language Integrated Queries
System.Linq
in your application

2.11 .NET Array Types:


Refer page no: 23
In .Net, array you create is automatically derived from System.Array. This class defines a number of helpful
methods that make working with arrays much more palatable.
Table 2.7: Members of the Array type

Member Meaning in life


BinarySearch() This static method searches an array for a given item.
Clear() This static method sets a range of elements in the array to empty values(0 for value
types; null for reference types).
CopyTo() This method is used to copy elements from the source array into the destination
array.
Length This read-only property is used to determine the number of elements in an array.
Rank This property returns the number of dimensions of the current array.
Reverse() This static method reverses the contents of a one-dimensional array.
Sort() This method sorts a one-dimensional array of intrinsic types.

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 27 | 29


Module – 1 20MCA42
Example 2.8:

using System;
namespace Examples{
class ArrayBaseDemo{
static void dumpArray(string[] a){
foreach(string i in a ){
Console.WriteLine(i);
}
Console.WriteLine();
}
static void Main(){
string[] a = { "alpha", "beta", "gamma", "delta",
"epsilon" };
Console.WriteLine("The Array:");
dumpArray(a);
Array.Reverse(a);
Console.WriteLine("The Reverse list:");
dumpArray(a);
Array.Clear(a, 1, 2);
Console.WriteLine("After cleared list:");
dumpArray(a);
Console.ReadKey();
} } }

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 28 | 29


Module – 1 20MCA42
Questions
Chapter 1 - Getting started with .NET Framework 4.0 Marks

1. What is .NET Framework? Explain the benefits of .Net framework. 05


2. Discuss the architecture of .Net Framework 4.0 with a neat diagram. 05
With a neat diagram, explain the workflow that takes place between .NET source code, ●NET
3. 09
compiler and the execution engine.
4. Briefly discuss the role of Common Language Runtime (CLR) in .NET Framework with a
10
neat diagram.
5. Differences between managed code and unmanaged code. 04
6. Explain the role of Common Type System. 05
7. What is Common Language Specification? Explain 03
8. Differentiate between single file and multi file assembly. 05
9. What is Assembly? List out the information stored in assembly manifest. 05
10. Explain the role of Metadata and Assemblies. 08
11. Write a Short notes on:
i. JIT Compiler v. Private and Shared assemblies Each
ii. Strong Names assembly vi. Global Assembly Cache carries
iii. Static and Dynamic assemblies vii. Window Communication Foundation 05
iv. Windows CardSpace and LINQ
12. Explain windows workflow foundation architecture with a neat diagram. 05
Chapter 2 – Introducing C#
1. Write C# console application program and discuss the variations of the main method. 06
2. Explain value types and reference types. List the differences. 06
3. Explain .Net Array types. Give an example for the members of System.Array class. 08
4. Describe .Net struct types with an example 05
5. What are enumerations? What is the default data type of the members? How would you
06
change the default type? Give an example.
6. What are Jagged Arrays? Write a program to find the sum of all elements in a jagged array of
08
3 inner arrays.
7. Bring out the differences between dynamic types and object types. 04
8. Write a C# program to the row sum and column sun of given matrix 08
9. Write a program to find the sum of even elements in even rows in a given jagged array. 06
10. Write a C# program on boxing, unboxing and bad unboxing. 06
11. Write a Short notes on:
i. Verbatim string literal iii. Boxing and unboxing v. foreach
ii. Identifiers and Keywords iv. Type Conversion vi. Object Type

12. What are namespaces? List and explain the purpose of any three namespaces 05

Suma M G, Asst. Prof, Dept. of MCA, RNSIT 29 | 29

You might also like