SlideShare a Scribd company logo
In this session, you will learn to:
Explain the purpose of base system types
Implement generics, Nullable types, exception classes, and
attributes
Implement comparison interfaces and the IConvertible,
ICloneable, IFormattable, and IDisposable interfaces
Objectives
What are System Types?
System types are pre-defined data types.
Based on how compilers manage data types, software
development environments can be classified into two types:
Loosely typed
Strongly typed
.NET Framework provides a common set of data types called
Common Type System (CTS).
Examining Primary System Types
Strongly typed
environment
What are Value Types?
Value types are types that contain the actual data assigned to
them instead of a reference to the data.
There are two types of value types:
Built-in types: These are also referred to as simple or primitive
value types. Some of the built-in types are:
System.Char
System.Int32
System.Single
User-defined value types: These are custom value types that make
the .NET Framework fully extensible. Some of the user-defined
value types are:
Structure
Constant
Enumeration
Examining Primary System Types (Contd.)
What are Reference Types?
Reference types are system types that contain a reference to
assigned data instead of the actual data.
The data of a reference type is stored on a heap, but its
reference is stored on a stack.
There are two types of reference types:
Classes
Interfaces
Stack
A=“Hi” HiA
Heap
Examining Primary System Types (Contd.)
What is Boxing and Unboxing?
Boxing: It is the conversion of a value type to a reference type.
Unboxing: It is the explicit conversion of a reference type to a
value type.
Boxing
Unboxing
Value Type
Reference
Type
Examining Primary System Types (Contd.)
The following code example implements boxing:
int a = 100;
object o = a;
a = 200;
Console.WriteLine("The value-type value = {0}",
a);
Console.WriteLine("The object-type value = {0}",
o);
Examining Primary System Types (Contd.)
The following code example implements unboxing:
int a = 1;
Object o = a;
a = 100;
Console.WriteLine(a);
a = (int) o;
Console.WriteLine(a);
Examining Primary System Types (Contd.)
What is Casting?
Data type conversion in the .NET Framework is
known as type casting.
Type casting is of two types:
Implicit: Implicit casting is also called widening conversion because
narrow data types are converted to wide data types.
Explicit: Explicit casting is also called narrowing conversion
because wide data types are converted to narrow data types.
Single Double
Implicit casting
Explicit casting
Examining Primary System Types (Contd.)
The following code example shows the implementation of
implicit casting:
Int32 a;
Double b;
a = 100;
b = a;
The following code example shows the implementation of
explicit casting:
Int64 a = 100;
Int32 b = 0;
b = (Int32) a;
Examining Primary System Types (Contd.)
What is type safety?
Just a minute
Answer
Type safety is a situation where a compiler allows only those
values that comply with the assigned data type to be stored in
the variable.
What are Generics?
Generics are used to create type-safe collections for both
reference and value types.
By using generic types, you can create a method, class,
structure, or an interface in your code without specifying any
fixed data type.
They provide advantages such as reusability, type safety and
performance.
Working with Special System Types
The following code snippet defines a generic class
called CommonData:
class Program
{
static void Main(string[] args)
{
CommonData<string>name = new
CommonData<string>();
name.Value = ".NET Framework";
CommonData<float>version = new
CommonData<float>();
version.Value = 2.0F;
Console.WriteLine(name.Value);
Console.WriteLine(version.Value);
} }
Working with Special System Types (Contd.)
public class CommonData<T>
{
private T _data;
public T Value
{
get
{
return this._data;
}
set
{
this._data = value;
}
}
}
Working with Special System Types (Contd.)
Advantages of generics
Reusability: A single generic type definition can be used for
multiple scenarios in the same code, without any alterations.
Type safety: Generic data types provide better type safety,
especially in situations where collections are used.
Performance: Generic types perform better than normal
system types because they reduce the need for boxing,
unboxing, and type casting the variables or objects.
Working with Special System Types (Contd.)
What are generics?
Just a minute
Answer
The .NET Framework 2.0 provides generics that you can use to
create type-safe collections for both reference and value types.
Assign Null Values to Value Types by Using Nullable
Data Types
By using a Nullable data type you can assign null values for
value type variables.
Nullable data types are expanded only at run time.
The following code snippet shows implementation of the
Nullable data type for the field date of anniversary:
public Nullable<DateTime> Anniversary
{ get
{return this._mAnniversary;}
set
{if (this._married)
this._mAnniversary = value;
else
this._mAnniversary = null;
} }
Working with Special System Types (Contd.)
Can value types be assigned a null value, and what value
will they then hold?
Just a minute
Answer
Value types can be assigned a null value. However, when you
assign a null value to a value type variable, only its default value
is assigned to the value type variable. For example, in the case
of an integer value type variable, the default value assigned will
be zero.
Handle Exceptions in Applications by Using Exception
Classes
Exceptions are error conditions or unexpected behavior that a
program may encounter at run time.
.Net Framework 2.0 provides two types of exception handling:
Predefined exception handling
User-defined exception handling
The try, catch, and finally block is used to handle exceptions
The throw statement is used to explicitly signal the
occurrence of an exception during program execution.
The exceptions are derived from the System.Exception
class for handling exceptions in the .Net Framework.
Working with Special System Types (Contd.)
The following code example uses a try/catch block to
catch a possible predefined exception:
ArgumentOutOfRangeException.
class ExceptionHandling
{
public static void Main()
{
int[] sourceIntArray={1,2,3};
int[] destinationIntArray={5,6,7,8};
try
{
Array.Copy(sourceIntArray,
destinationIntArray,-1);
}
Working with Special System Types (Contd.)
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine("Argument Out
Of Range Exception: {0}",e);
}
finally
{
Console.WriteLine("Finally block
is always executed.");
}
}
}
Working with Special System Types (Contd.)
Customize Code Behavior by Using Attributes
Attributes are an extended way to document code.
Attributes are of two types:
Predefined attributes: The following code snippet shows
declaration of System.ObsoleteAttribute:
public class ObsoleteAttributeExample
{
[Obsolete("This function is obsolete")]
public static int Subtract( int a, int b)
{
return (a-b);
}
public static void Main()
{
int result = Subtract(9,2);
}
}
Working with Special System Types (Contd.)
Custom attributes: The following code snippet defines a custom
attribute class MaxLengthAttribute:
[AttributeUsage(AttributeTargets.Field)]
class MaxLengthAttribute : Attribute
{ private int _max;
public MaxLengthAttribute(int max)
{ this._max = max;}
public bool IsValidLength(string value)
{
if (value == null)
return true;
else
if (this._max <= value.Length)
return true;
else
return false;
}
}
Working with Special System Types (Contd.)
What are Interfaces?
An interface looks like a class, but has no implementation. It
only contains definitions of events, indexers, methods, and
properties.
The classes and structures provide an implementation for each
member declared in the interface.
The following code example shows how you can define an
interface named Ishape:
interface IShape
{
int Area();
}
Working with Interfaces
Does an interface contain implementation?
Just a minute
Answer
An interface looks like a class, but it has no implementation. It
only contains definitions of events, indexers, methods, and
properties.
Compare Reference Types by Using Comparison Interfaces
The .NET Framework provides comparison interfaces for
comparing reference types.
The two most common types of comparison interfaces are:
IComparable: It defines a generalized comparison method that a
value type or class implements to create a type-specific
comparison method.
IEquatable: This interface applies only to generics. This
interface provides a generalized method to perform an equality
check between two instances of the same type.
Working with Interfaces (Contd.)
Comparison Interface
Reference
type 2
Reference
type 1
Convert a Reference Type by Using the IConvertible
Interface
IConvertible interface can be used to convert an object to
one of the CLR types.
IConvertible interface converts the value of an instance of
the implementing type to the equivalent data type under CTS.
The following code snippet shows its implementation of
IConvertible interface :
class Decision : IConvertible
{ bool _agree;
DateTime
IConvertible.ToDateTime(IFormatProvider
provider)
{throw new InvalidCastException("Cannot cast
to DateTime"); }
//... other IConvertible Methods
}
Working with Interfaces (Contd.)
Create a Copy of a Reference Type by Using the
ICloneable Interface
The ICloneable interface is used to create a new instance of
an object with the same value as an existing instance.
.Net Framework supports two types of cloning:
Shallow Cloning: Involves copying an object without copying any
references.
Deep Cloning: Involves making a copy of an object and any
references to other objects.
Working with Interfaces (Contd.)
Format System Data to a String by Using the
IFormattable Interface
The IFormattable interface can be used for formatting the
value of the current instance by using the specified format.
The interface defines the ToString method to implement the
same.
The System.Object class provides a default implementation
of the ToString method.
Working with Interfaces (Contd.)
Dispose Unmanaged Resources by Using the
IDisposable Interface
A special component of the .Net Framework called the garbage
collector manages the release of object memory on the heap
automatically.
The garbage collector periodically looks for unused objects on
the heap and deallocates their memory.
In the .NET Framework, unmanaged resources can be
released explicitly by implementing the IDisposable
interface.
Garbage
CollectorMemory
Garbage
Collection
Working with Interfaces (Contd.)
The following code example shows the implementation of
the IDisposable interface in a class named
CustomerDataAccess:
public class CustomerDataAccess : IDisposable
{
protected virtual void Dispose(bool
disposing)
{ if(disposing)
{
// call dispose on any objects referenced by this
object }
// release unmanaged resources
}
Working with Interfaces (Contd.)
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
~CustomerDataAccess()
{
this.Dispose(false);
}
}
Working with Interfaces (Contd.)
What is garbage collection?
Just a minute
Answer
Garbage collection is a form of automatic memory management.
The garbage collector manages the allocation and release of
memory for your application.
In this session, you learned that:
Base system types represent a set of predefined data types.
Boxing and unboxing can be used for conversion between
value types and reference types.
Generic types are used to create a method, class, structure, or
an interface without specifying any fixed data type.
Nullable data type is used to assign null values for value
type variables.
Predefined exceptions that the CLR generates or a custom
exception class can be used to handle exceptions.
Attributes are used to customize code behavior at run time.
Interfaces are used to specify a set of properties that, on
implementation, perform a specific functionality.
The commonly used interfaces are IComparable,
IEquatable, IConvertible, ICloneable, and
IFormattable.
Summary

More Related Content

What's hot

Intake 37 5
Intake 37 5Intake 37 5
Intake 37 5
Mahmoud Ouf
 
Intake 37 6
Intake 37 6Intake 37 6
Intake 37 6
Mahmoud Ouf
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
DevaKumari Vijay
 
Intake 38 2
Intake 38 2Intake 38 2
Intake 38 2
Mahmoud Ouf
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
DevaKumari Vijay
 
Intake 37 1
Intake 37 1Intake 37 1
Intake 37 1
Mahmoud Ouf
 
Creating and destroying objects
Creating and destroying objectsCreating and destroying objects
Creating and destroying objects
Sandeep Chawla
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
DevaKumari Vijay
 
C# Constructors
C# ConstructorsC# Constructors
C# Constructors
Prem Kumar Badri
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++M Hussnain Ali
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
Mahmoud Ouf
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
Shohan Ahmed
 
Beginning linq
Beginning linqBeginning linq
Beginning linq
Shikha Gupta
 
Think Different: Objective-C for the .NET developer
Think Different: Objective-C for the .NET developerThink Different: Objective-C for the .NET developer
Think Different: Objective-C for the .NET developer
Shawn Price
 
Lecture02 java
Lecture02 javaLecture02 java
Lecture02 java
jawidAhmadRohani
 

What's hot (20)

Intake 37 5
Intake 37 5Intake 37 5
Intake 37 5
 
Intake 37 6
Intake 37 6Intake 37 6
Intake 37 6
 
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysUnit 2-data types,Variables,Operators,Conitionals,loops and arrays
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
 
Intake 38 2
Intake 38 2Intake 38 2
Intake 38 2
 
Unit 4 exceptions and threads
Unit 4 exceptions and threadsUnit 4 exceptions and threads
Unit 4 exceptions and threads
 
Intake 37 1
Intake 37 1Intake 37 1
Intake 37 1
 
Creating and destroying objects
Creating and destroying objectsCreating and destroying objects
Creating and destroying objects
 
Hemajava
HemajavaHemajava
Hemajava
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
C# Constructors
C# ConstructorsC# Constructors
C# Constructors
 
My c++
My c++My c++
My c++
 
M C6java3
M C6java3M C6java3
M C6java3
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
Beginning linq
Beginning linqBeginning linq
Beginning linq
 
Think Different: Objective-C for the .NET developer
Think Different: Objective-C for the .NET developerThink Different: Objective-C for the .NET developer
Think Different: Objective-C for the .NET developer
 
Lecture02 java
Lecture02 javaLecture02 java
Lecture02 java
 

Viewers also liked

Net framework session02
Net framework session02Net framework session02
Net framework session02
Vivek chan
 
.NET Overview
.NET Overview.NET Overview
.NET Overview
Greg Sohl
 
Garbage Collection In Micorosoft
Garbage Collection In  MicorosoftGarbage Collection In  Micorosoft
Garbage Collection In Micorosoft
SmithaNatarajamurthy
 
Memory Management & Garbage Collection
Memory Management & Garbage CollectionMemory Management & Garbage Collection
Memory Management & Garbage Collection
Abhishek Sur
 
Cisco CCNAX .200 120
Cisco CCNAX .200 120Cisco CCNAX .200 120
Cisco CCNAX .200 120
abdulquyyum
 
Net framework session03
Net framework session03Net framework session03
Net framework session03
Vivek chan
 
Performance evaluation-of-ieee-802.11p-for-vehicular-communication-networks
Performance evaluation-of-ieee-802.11p-for-vehicular-communication-networksPerformance evaluation-of-ieee-802.11p-for-vehicular-communication-networks
Performance evaluation-of-ieee-802.11p-for-vehicular-communication-networksAmir Jafari
 
Comp Tia Flashcards Set 4 (25 cards) IEEE - MPEG
Comp Tia Flashcards Set 4 (25 cards) IEEE - MPEGComp Tia Flashcards Set 4 (25 cards) IEEE - MPEG
Comp Tia Flashcards Set 4 (25 cards) IEEE - MPEGSue Long Smith
 
Comp tia flashcards set 3 (25 cards) esd ide
Comp tia flashcards set 3 (25 cards) esd   ideComp tia flashcards set 3 (25 cards) esd   ide
Comp tia flashcards set 3 (25 cards) esd ideSue Long Smith
 
Comp Tia Flashcards Set 5 (25 cards) NAS - PVC
Comp Tia Flashcards Set 5 (25 cards) NAS - PVCComp Tia Flashcards Set 5 (25 cards) NAS - PVC
Comp Tia Flashcards Set 5 (25 cards) NAS - PVCSue Long Smith
 
Comp Tia Flashcards Set 6 (25 cards) RAID - SNMP
Comp Tia Flashcards Set 6 (25 cards) RAID - SNMPComp Tia Flashcards Set 6 (25 cards) RAID - SNMP
Comp Tia Flashcards Set 6 (25 cards) RAID - SNMPSue Long Smith
 
Comp tia flashcards set 2 (25 cards) cpu erd
Comp tia flashcards set 2 (25 cards) cpu   erdComp tia flashcards set 2 (25 cards) cpu   erd
Comp tia flashcards set 2 (25 cards) cpu erdSue Long Smith
 
CCNA Lab 1-Configuring a Switch Part I
CCNA Lab 1-Configuring a Switch Part ICCNA Lab 1-Configuring a Switch Part I
CCNA Lab 1-Configuring a Switch Part I
Amir Jafari
 
Comp tia flashcards set 1 (15 cards) acpi cmos
Comp tia flashcards set 1 (15 cards) acpi   cmosComp tia flashcards set 1 (15 cards) acpi   cmos
Comp tia flashcards set 1 (15 cards) acpi cmosSue Long Smith
 
CCNA Lab 2-Configuring a Switch Part II
CCNA Lab 2-Configuring a Switch Part IICCNA Lab 2-Configuring a Switch Part II
CCNA Lab 2-Configuring a Switch Part II
Amir Jafari
 
CCNA Lab 4-Configuring EtherChannels and optimizing Spanning Tree Protocol on...
CCNA Lab 4-Configuring EtherChannels and optimizing Spanning Tree Protocol on...CCNA Lab 4-Configuring EtherChannels and optimizing Spanning Tree Protocol on...
CCNA Lab 4-Configuring EtherChannels and optimizing Spanning Tree Protocol on...
Amir Jafari
 

Viewers also liked (20)

Net framework session02
Net framework session02Net framework session02
Net framework session02
 
.NET Overview
.NET Overview.NET Overview
.NET Overview
 
Working in Visual Studio.Net
Working in Visual Studio.NetWorking in Visual Studio.Net
Working in Visual Studio.Net
 
Garbage Collection In Micorosoft
Garbage Collection In  MicorosoftGarbage Collection In  Micorosoft
Garbage Collection In Micorosoft
 
Introduction to Visual Studio.NET
Introduction to Visual Studio.NETIntroduction to Visual Studio.NET
Introduction to Visual Studio.NET
 
Memory Management & Garbage Collection
Memory Management & Garbage CollectionMemory Management & Garbage Collection
Memory Management & Garbage Collection
 
Cisco CCNAX .200 120
Cisco CCNAX .200 120Cisco CCNAX .200 120
Cisco CCNAX .200 120
 
Net framework session03
Net framework session03Net framework session03
Net framework session03
 
Performance evaluation-of-ieee-802.11p-for-vehicular-communication-networks
Performance evaluation-of-ieee-802.11p-for-vehicular-communication-networksPerformance evaluation-of-ieee-802.11p-for-vehicular-communication-networks
Performance evaluation-of-ieee-802.11p-for-vehicular-communication-networks
 
Comp Tia Flashcards Set 4 (25 cards) IEEE - MPEG
Comp Tia Flashcards Set 4 (25 cards) IEEE - MPEGComp Tia Flashcards Set 4 (25 cards) IEEE - MPEG
Comp Tia Flashcards Set 4 (25 cards) IEEE - MPEG
 
Comp tia flashcards set 3 (25 cards) esd ide
Comp tia flashcards set 3 (25 cards) esd   ideComp tia flashcards set 3 (25 cards) esd   ide
Comp tia flashcards set 3 (25 cards) esd ide
 
Lakeview Squares
Lakeview SquaresLakeview Squares
Lakeview Squares
 
Comp Tia Flashcards Set 5 (25 cards) NAS - PVC
Comp Tia Flashcards Set 5 (25 cards) NAS - PVCComp Tia Flashcards Set 5 (25 cards) NAS - PVC
Comp Tia Flashcards Set 5 (25 cards) NAS - PVC
 
Comp Tia Flashcards Set 6 (25 cards) RAID - SNMP
Comp Tia Flashcards Set 6 (25 cards) RAID - SNMPComp Tia Flashcards Set 6 (25 cards) RAID - SNMP
Comp Tia Flashcards Set 6 (25 cards) RAID - SNMP
 
Comp tia flashcards set 2 (25 cards) cpu erd
Comp tia flashcards set 2 (25 cards) cpu   erdComp tia flashcards set 2 (25 cards) cpu   erd
Comp tia flashcards set 2 (25 cards) cpu erd
 
CCNA Lab 1-Configuring a Switch Part I
CCNA Lab 1-Configuring a Switch Part ICCNA Lab 1-Configuring a Switch Part I
CCNA Lab 1-Configuring a Switch Part I
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 
Comp tia flashcards set 1 (15 cards) acpi cmos
Comp tia flashcards set 1 (15 cards) acpi   cmosComp tia flashcards set 1 (15 cards) acpi   cmos
Comp tia flashcards set 1 (15 cards) acpi cmos
 
CCNA Lab 2-Configuring a Switch Part II
CCNA Lab 2-Configuring a Switch Part IICCNA Lab 2-Configuring a Switch Part II
CCNA Lab 2-Configuring a Switch Part II
 
CCNA Lab 4-Configuring EtherChannels and optimizing Spanning Tree Protocol on...
CCNA Lab 4-Configuring EtherChannels and optimizing Spanning Tree Protocol on...CCNA Lab 4-Configuring EtherChannels and optimizing Spanning Tree Protocol on...
CCNA Lab 4-Configuring EtherChannels and optimizing Spanning Tree Protocol on...
 

Similar to Net framework session01

LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
Tabassum Ghulame Mustafa
 
Chapter 1 Presentation
Chapter 1 PresentationChapter 1 Presentation
Chapter 1 Presentation
guest0d6229
 
3rd june
3rd june3rd june
03 oo with-c-sharp
03 oo with-c-sharp03 oo with-c-sharp
03 oo with-c-sharpNaved khan
 
Net framework session01
Net framework session01Net framework session01
Net framework session01Niit Care
 
C#
C#C#
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
megersaoljira
 
C# Unit 1 notes
C# Unit 1 notesC# Unit 1 notes
C# Unit 1 notes
Sudarshan Dhondaley
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
InfinityWorld3
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
ssusera0bb35
 
Visual Basic User Interface -IV
Visual Basic User Interface -IVVisual Basic User Interface -IV
Visual Basic User Interface -IV
Sharbani Bhattacharya
 
X++ 1.pptx
X++ 1.pptxX++ 1.pptx
X++ 1.pptx
Vijay Shukla
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
SAMIR BHOGAYTA
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
Vishwa Mohan
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
PriyadarshiniS28
 
C# note
C# noteC# note
Chapter 1 introduction to .net
Chapter 1 introduction to .netChapter 1 introduction to .net
Chapter 1 introduction to .net
Rahul Bhoge
 
Csharp
CsharpCsharp
Csharp
vinayabburi
 

Similar to Net framework session01 (20)

LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
 
Chapter 1 Presentation
Chapter 1 PresentationChapter 1 Presentation
Chapter 1 Presentation
 
3rd june
3rd june3rd june
3rd june
 
03 oo with-c-sharp
03 oo with-c-sharp03 oo with-c-sharp
03 oo with-c-sharp
 
Net framework session01
Net framework session01Net framework session01
Net framework session01
 
C#
C#C#
C#
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
 
C# Unit 1 notes
C# Unit 1 notesC# Unit 1 notes
C# Unit 1 notes
 
C#ppt
C#pptC#ppt
C#ppt
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
 
Visual Basic User Interface -IV
Visual Basic User Interface -IVVisual Basic User Interface -IV
Visual Basic User Interface -IV
 
X++ 1.pptx
X++ 1.pptxX++ 1.pptx
X++ 1.pptx
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
C# note
C# noteC# note
C# note
 
Chapter 1 introduction to .net
Chapter 1 introduction to .netChapter 1 introduction to .net
Chapter 1 introduction to .net
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
Csharp
CsharpCsharp
Csharp
 

More from Vivek chan

Deceptive Marketing.pdf
Deceptive Marketing.pdfDeceptive Marketing.pdf
Deceptive Marketing.pdf
Vivek chan
 
brain controled wheel chair.pdf
brain controled wheel chair.pdfbrain controled wheel chair.pdf
brain controled wheel chair.pdf
Vivek chan
 
Mechanism of fullerene synthesis in the ARC REACTOR (Vivek Chan 2013)
Mechanism of fullerene synthesis in the ARC REACTOR (Vivek Chan 2013)Mechanism of fullerene synthesis in the ARC REACTOR (Vivek Chan 2013)
Mechanism of fullerene synthesis in the ARC REACTOR (Vivek Chan 2013)
Vivek chan
 
Manav dharma shashtra tatha shashan paddati munshiram jigyasu
Manav dharma shashtra tatha shashan paddati   munshiram jigyasuManav dharma shashtra tatha shashan paddati   munshiram jigyasu
Manav dharma shashtra tatha shashan paddati munshiram jigyasu
Vivek chan
 
Self driving and connected cars fooling sensors and tracking drivers
Self driving and connected cars fooling sensors and tracking driversSelf driving and connected cars fooling sensors and tracking drivers
Self driving and connected cars fooling sensors and tracking drivers
Vivek chan
 
EEG Acquisition Device to Control Wheelchair Using Thoughts
EEG Acquisition Device to Control Wheelchair Using ThoughtsEEG Acquisition Device to Control Wheelchair Using Thoughts
EEG Acquisition Device to Control Wheelchair Using Thoughts
Vivek chan
 
Vivek Chan | Technology Consultant
Vivek Chan | Technology Consultant Vivek Chan | Technology Consultant
Vivek Chan | Technology Consultant
Vivek chan
 
Vivek Chan | Technology Consultant
Vivek Chan | Technology Consultant Vivek Chan | Technology Consultant
Vivek Chan | Technology Consultant
Vivek chan
 
Full Shri Ramcharitmanas in Hindi Complete With Meaning (Ramayana)
Full Shri Ramcharitmanas in Hindi Complete With Meaning (Ramayana)Full Shri Ramcharitmanas in Hindi Complete With Meaning (Ramayana)
Full Shri Ramcharitmanas in Hindi Complete With Meaning (Ramayana)
Vivek chan
 
04 intel v_tune_session_05
04 intel v_tune_session_0504 intel v_tune_session_05
04 intel v_tune_session_05
Vivek chan
 
03 intel v_tune_session_04
03 intel v_tune_session_0403 intel v_tune_session_04
03 intel v_tune_session_04
Vivek chan
 
02 intel v_tune_session_02
02 intel v_tune_session_0202 intel v_tune_session_02
02 intel v_tune_session_02
Vivek chan
 
01 intel v_tune_session_01
01 intel v_tune_session_0101 intel v_tune_session_01
01 intel v_tune_session_01
Vivek chan
 
09 intel v_tune_session_13
09 intel v_tune_session_1309 intel v_tune_session_13
09 intel v_tune_session_13
Vivek chan
 
07 intel v_tune_session_10
07 intel v_tune_session_1007 intel v_tune_session_10
07 intel v_tune_session_10
Vivek chan
 
02 asp.net session02
02 asp.net session0202 asp.net session02
02 asp.net session02
Vivek chan
 
01 asp.net session01
01 asp.net session0101 asp.net session01
01 asp.net session01
Vivek chan
 
16 asp.net session23
16 asp.net session2316 asp.net session23
16 asp.net session23
Vivek chan
 
15 asp.net session22
15 asp.net session2215 asp.net session22
15 asp.net session22
Vivek chan
 
14 asp.net session20
14 asp.net session2014 asp.net session20
14 asp.net session20
Vivek chan
 

More from Vivek chan (20)

Deceptive Marketing.pdf
Deceptive Marketing.pdfDeceptive Marketing.pdf
Deceptive Marketing.pdf
 
brain controled wheel chair.pdf
brain controled wheel chair.pdfbrain controled wheel chair.pdf
brain controled wheel chair.pdf
 
Mechanism of fullerene synthesis in the ARC REACTOR (Vivek Chan 2013)
Mechanism of fullerene synthesis in the ARC REACTOR (Vivek Chan 2013)Mechanism of fullerene synthesis in the ARC REACTOR (Vivek Chan 2013)
Mechanism of fullerene synthesis in the ARC REACTOR (Vivek Chan 2013)
 
Manav dharma shashtra tatha shashan paddati munshiram jigyasu
Manav dharma shashtra tatha shashan paddati   munshiram jigyasuManav dharma shashtra tatha shashan paddati   munshiram jigyasu
Manav dharma shashtra tatha shashan paddati munshiram jigyasu
 
Self driving and connected cars fooling sensors and tracking drivers
Self driving and connected cars fooling sensors and tracking driversSelf driving and connected cars fooling sensors and tracking drivers
Self driving and connected cars fooling sensors and tracking drivers
 
EEG Acquisition Device to Control Wheelchair Using Thoughts
EEG Acquisition Device to Control Wheelchair Using ThoughtsEEG Acquisition Device to Control Wheelchair Using Thoughts
EEG Acquisition Device to Control Wheelchair Using Thoughts
 
Vivek Chan | Technology Consultant
Vivek Chan | Technology Consultant Vivek Chan | Technology Consultant
Vivek Chan | Technology Consultant
 
Vivek Chan | Technology Consultant
Vivek Chan | Technology Consultant Vivek Chan | Technology Consultant
Vivek Chan | Technology Consultant
 
Full Shri Ramcharitmanas in Hindi Complete With Meaning (Ramayana)
Full Shri Ramcharitmanas in Hindi Complete With Meaning (Ramayana)Full Shri Ramcharitmanas in Hindi Complete With Meaning (Ramayana)
Full Shri Ramcharitmanas in Hindi Complete With Meaning (Ramayana)
 
04 intel v_tune_session_05
04 intel v_tune_session_0504 intel v_tune_session_05
04 intel v_tune_session_05
 
03 intel v_tune_session_04
03 intel v_tune_session_0403 intel v_tune_session_04
03 intel v_tune_session_04
 
02 intel v_tune_session_02
02 intel v_tune_session_0202 intel v_tune_session_02
02 intel v_tune_session_02
 
01 intel v_tune_session_01
01 intel v_tune_session_0101 intel v_tune_session_01
01 intel v_tune_session_01
 
09 intel v_tune_session_13
09 intel v_tune_session_1309 intel v_tune_session_13
09 intel v_tune_session_13
 
07 intel v_tune_session_10
07 intel v_tune_session_1007 intel v_tune_session_10
07 intel v_tune_session_10
 
02 asp.net session02
02 asp.net session0202 asp.net session02
02 asp.net session02
 
01 asp.net session01
01 asp.net session0101 asp.net session01
01 asp.net session01
 
16 asp.net session23
16 asp.net session2316 asp.net session23
16 asp.net session23
 
15 asp.net session22
15 asp.net session2215 asp.net session22
15 asp.net session22
 
14 asp.net session20
14 asp.net session2014 asp.net session20
14 asp.net session20
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

Net framework session01

  • 1. In this session, you will learn to: Explain the purpose of base system types Implement generics, Nullable types, exception classes, and attributes Implement comparison interfaces and the IConvertible, ICloneable, IFormattable, and IDisposable interfaces Objectives
  • 2. What are System Types? System types are pre-defined data types. Based on how compilers manage data types, software development environments can be classified into two types: Loosely typed Strongly typed .NET Framework provides a common set of data types called Common Type System (CTS). Examining Primary System Types Strongly typed environment
  • 3. What are Value Types? Value types are types that contain the actual data assigned to them instead of a reference to the data. There are two types of value types: Built-in types: These are also referred to as simple or primitive value types. Some of the built-in types are: System.Char System.Int32 System.Single User-defined value types: These are custom value types that make the .NET Framework fully extensible. Some of the user-defined value types are: Structure Constant Enumeration Examining Primary System Types (Contd.)
  • 4. What are Reference Types? Reference types are system types that contain a reference to assigned data instead of the actual data. The data of a reference type is stored on a heap, but its reference is stored on a stack. There are two types of reference types: Classes Interfaces Stack A=“Hi” HiA Heap Examining Primary System Types (Contd.)
  • 5. What is Boxing and Unboxing? Boxing: It is the conversion of a value type to a reference type. Unboxing: It is the explicit conversion of a reference type to a value type. Boxing Unboxing Value Type Reference Type Examining Primary System Types (Contd.)
  • 6. The following code example implements boxing: int a = 100; object o = a; a = 200; Console.WriteLine("The value-type value = {0}", a); Console.WriteLine("The object-type value = {0}", o); Examining Primary System Types (Contd.)
  • 7. The following code example implements unboxing: int a = 1; Object o = a; a = 100; Console.WriteLine(a); a = (int) o; Console.WriteLine(a); Examining Primary System Types (Contd.)
  • 8. What is Casting? Data type conversion in the .NET Framework is known as type casting. Type casting is of two types: Implicit: Implicit casting is also called widening conversion because narrow data types are converted to wide data types. Explicit: Explicit casting is also called narrowing conversion because wide data types are converted to narrow data types. Single Double Implicit casting Explicit casting Examining Primary System Types (Contd.)
  • 9. The following code example shows the implementation of implicit casting: Int32 a; Double b; a = 100; b = a; The following code example shows the implementation of explicit casting: Int64 a = 100; Int32 b = 0; b = (Int32) a; Examining Primary System Types (Contd.)
  • 10. What is type safety? Just a minute Answer Type safety is a situation where a compiler allows only those values that comply with the assigned data type to be stored in the variable.
  • 11. What are Generics? Generics are used to create type-safe collections for both reference and value types. By using generic types, you can create a method, class, structure, or an interface in your code without specifying any fixed data type. They provide advantages such as reusability, type safety and performance. Working with Special System Types
  • 12. The following code snippet defines a generic class called CommonData: class Program { static void Main(string[] args) { CommonData<string>name = new CommonData<string>(); name.Value = ".NET Framework"; CommonData<float>version = new CommonData<float>(); version.Value = 2.0F; Console.WriteLine(name.Value); Console.WriteLine(version.Value); } } Working with Special System Types (Contd.)
  • 13. public class CommonData<T> { private T _data; public T Value { get { return this._data; } set { this._data = value; } } } Working with Special System Types (Contd.)
  • 14. Advantages of generics Reusability: A single generic type definition can be used for multiple scenarios in the same code, without any alterations. Type safety: Generic data types provide better type safety, especially in situations where collections are used. Performance: Generic types perform better than normal system types because they reduce the need for boxing, unboxing, and type casting the variables or objects. Working with Special System Types (Contd.)
  • 15. What are generics? Just a minute Answer The .NET Framework 2.0 provides generics that you can use to create type-safe collections for both reference and value types.
  • 16. Assign Null Values to Value Types by Using Nullable Data Types By using a Nullable data type you can assign null values for value type variables. Nullable data types are expanded only at run time. The following code snippet shows implementation of the Nullable data type for the field date of anniversary: public Nullable<DateTime> Anniversary { get {return this._mAnniversary;} set {if (this._married) this._mAnniversary = value; else this._mAnniversary = null; } } Working with Special System Types (Contd.)
  • 17. Can value types be assigned a null value, and what value will they then hold? Just a minute Answer Value types can be assigned a null value. However, when you assign a null value to a value type variable, only its default value is assigned to the value type variable. For example, in the case of an integer value type variable, the default value assigned will be zero.
  • 18. Handle Exceptions in Applications by Using Exception Classes Exceptions are error conditions or unexpected behavior that a program may encounter at run time. .Net Framework 2.0 provides two types of exception handling: Predefined exception handling User-defined exception handling The try, catch, and finally block is used to handle exceptions The throw statement is used to explicitly signal the occurrence of an exception during program execution. The exceptions are derived from the System.Exception class for handling exceptions in the .Net Framework. Working with Special System Types (Contd.)
  • 19. The following code example uses a try/catch block to catch a possible predefined exception: ArgumentOutOfRangeException. class ExceptionHandling { public static void Main() { int[] sourceIntArray={1,2,3}; int[] destinationIntArray={5,6,7,8}; try { Array.Copy(sourceIntArray, destinationIntArray,-1); } Working with Special System Types (Contd.)
  • 20. catch (ArgumentOutOfRangeException e) { Console.WriteLine("Argument Out Of Range Exception: {0}",e); } finally { Console.WriteLine("Finally block is always executed."); } } } Working with Special System Types (Contd.)
  • 21. Customize Code Behavior by Using Attributes Attributes are an extended way to document code. Attributes are of two types: Predefined attributes: The following code snippet shows declaration of System.ObsoleteAttribute: public class ObsoleteAttributeExample { [Obsolete("This function is obsolete")] public static int Subtract( int a, int b) { return (a-b); } public static void Main() { int result = Subtract(9,2); } } Working with Special System Types (Contd.)
  • 22. Custom attributes: The following code snippet defines a custom attribute class MaxLengthAttribute: [AttributeUsage(AttributeTargets.Field)] class MaxLengthAttribute : Attribute { private int _max; public MaxLengthAttribute(int max) { this._max = max;} public bool IsValidLength(string value) { if (value == null) return true; else if (this._max <= value.Length) return true; else return false; } } Working with Special System Types (Contd.)
  • 23. What are Interfaces? An interface looks like a class, but has no implementation. It only contains definitions of events, indexers, methods, and properties. The classes and structures provide an implementation for each member declared in the interface. The following code example shows how you can define an interface named Ishape: interface IShape { int Area(); } Working with Interfaces
  • 24. Does an interface contain implementation? Just a minute Answer An interface looks like a class, but it has no implementation. It only contains definitions of events, indexers, methods, and properties.
  • 25. Compare Reference Types by Using Comparison Interfaces The .NET Framework provides comparison interfaces for comparing reference types. The two most common types of comparison interfaces are: IComparable: It defines a generalized comparison method that a value type or class implements to create a type-specific comparison method. IEquatable: This interface applies only to generics. This interface provides a generalized method to perform an equality check between two instances of the same type. Working with Interfaces (Contd.) Comparison Interface Reference type 2 Reference type 1
  • 26. Convert a Reference Type by Using the IConvertible Interface IConvertible interface can be used to convert an object to one of the CLR types. IConvertible interface converts the value of an instance of the implementing type to the equivalent data type under CTS. The following code snippet shows its implementation of IConvertible interface : class Decision : IConvertible { bool _agree; DateTime IConvertible.ToDateTime(IFormatProvider provider) {throw new InvalidCastException("Cannot cast to DateTime"); } //... other IConvertible Methods } Working with Interfaces (Contd.)
  • 27. Create a Copy of a Reference Type by Using the ICloneable Interface The ICloneable interface is used to create a new instance of an object with the same value as an existing instance. .Net Framework supports two types of cloning: Shallow Cloning: Involves copying an object without copying any references. Deep Cloning: Involves making a copy of an object and any references to other objects. Working with Interfaces (Contd.)
  • 28. Format System Data to a String by Using the IFormattable Interface The IFormattable interface can be used for formatting the value of the current instance by using the specified format. The interface defines the ToString method to implement the same. The System.Object class provides a default implementation of the ToString method. Working with Interfaces (Contd.)
  • 29. Dispose Unmanaged Resources by Using the IDisposable Interface A special component of the .Net Framework called the garbage collector manages the release of object memory on the heap automatically. The garbage collector periodically looks for unused objects on the heap and deallocates their memory. In the .NET Framework, unmanaged resources can be released explicitly by implementing the IDisposable interface. Garbage CollectorMemory Garbage Collection Working with Interfaces (Contd.)
  • 30. The following code example shows the implementation of the IDisposable interface in a class named CustomerDataAccess: public class CustomerDataAccess : IDisposable { protected virtual void Dispose(bool disposing) { if(disposing) { // call dispose on any objects referenced by this object } // release unmanaged resources } Working with Interfaces (Contd.)
  • 32. What is garbage collection? Just a minute Answer Garbage collection is a form of automatic memory management. The garbage collector manages the allocation and release of memory for your application.
  • 33. In this session, you learned that: Base system types represent a set of predefined data types. Boxing and unboxing can be used for conversion between value types and reference types. Generic types are used to create a method, class, structure, or an interface without specifying any fixed data type. Nullable data type is used to assign null values for value type variables. Predefined exceptions that the CLR generates or a custom exception class can be used to handle exceptions. Attributes are used to customize code behavior at run time. Interfaces are used to specify a set of properties that, on implementation, perform a specific functionality. The commonly used interfaces are IComparable, IEquatable, IConvertible, ICloneable, and IFormattable. Summary