Академический Документы
Профессиональный Документы
Культура Документы
WHAT IS .NET
AND
WHY DO WE NEED .NET?
DIFFERENT FROM Procedural language
Object oriented programming
• E.g. List<int>
• List<String> ------- generics
• Features of Generics
• Generics is a technique that improves your programs in many ways
such as:
• It helps you in code reuse, performance and type safety.
• You can create your own generic classes, methods, interfaces and
delegates.
• You can create generic collection classes. The .NET framework class
library contains many new generic collection classes in
System.Collections.Generic namespace.
• You can get information on the types used in generic data type at run-
time.
• Advantages of Generics
• Reusability: You can use a single generic type definition for multiple
purposes in the same code without any alterations. For example, you can
create a generic method to add two numbers. This method can be used to
add two integers as well as two floats without any modification in the code.
• Type Safety: Generic data types provide better type safety, especially in the
case of collections. When using generics you need to define the type of
objects to be passed to a collection. This helps the compiler to ensure that
only those object types that are defined in the definition can be passed to
the collection.
• Performance: Generic types provide better performance as compared to
normal system types because they reduce the need for boxing, unboxing,
and typecasting of variables or objects.
• Memory is not un-limited and we need to clean some used space in
order to make room for new objects,
• Garbage collector manages allocation and reclaiming of memory. GC
(Garbage collector) makes a trip to the heap and collects all objects
that are no longer used by the application and then makes them free
from memory.
• Destructor is a special method of a class and it is used in a class to destroy the object or
instances of classes. The destructor in c# will invoke automatically whenever the class
instances become unreachable.
•
• Following are the properties of destructor in c# programming language.
•
• In c#, destructors can be used only in classes and a class can contain only one destructor.
• The destructor in class can be represented by using tilde (~) operator
• The destructor in c# won’t accept any parameters and access modifiers.
• The destructor will invoke automatically, whenever an instance of class is no longer needed.
• The destructor automatically invoked by garbage collector whenever the class objects that are
no longer needed in application.