Generics
Generics
Generics
0 enhancement
Generics
Anonymous methods
Nullable Types
Iterators
Partial types
Generics
Generics
Valued Based:
- Value based Data types includes (numeric data types like float, int, etc.)
and enumerations and structures. And are allocated on the stack.
- Value based types could be quickly remove from the Stack / memory once
they fall out from the defining scope…
public void m()
{
int x=0;
console.writeline(x);
………..// x will pop out from the stack ..
}
Valued based v/s Referenced based type
Valued Based:
- Member to member copy is achieved on assigning one value type to
another.
public void m()
{
int x=20;
int y=x;
// now if I make j=200;
x= 20; (It will stay same)
}
- .Net Garbage collector destroy them. Till them they stay in the
memory.
Demo
la ss
it hc
e w
c tur
u
str
lace
p
Re
Pitch for Boxing & Unboxing
CLR works in the back ground and allocate a new object on the heap
plus assign the value(here 25).
& Unboxing
- To convert Reference type to Value type c# provides UNBoxing
mechanism.
Short y= (short)ob;
Demo
(D:\prabhjot\hcldemo2\hcldemo2)
& Unboxing
ers
ra mm
o g
pr
f or
blem
o
Pr
Automatic Unboxing
Demo
Demo
D:\prabhjot\windows\hcldcsharpdemo4
Generics
Generics
Generics
Demo
Demo
D:\prabhjot\hclcsharpdemo6gc
Generics
Generics
Generics
Generic Base Class
Generic Interface
Generic Delegates
Generic Lacks Operator Supports
C# Nullable Types
C# Nullable Types
This syntax is only legal with value type or value of array types. Any
attempts to create a nullable reference type will issue a compile
error.
Class Databasereader
{ //nullable Data field
public int? numbericValue;
public bool? boolValue=True;
//nullable return type
Allow classes, structs, and interfaces to be broken into multiple pieces stored in
different source files for easier development and maintenance.
C# 2005 introduces a new type modifier named partial that allows you to define a C#
type across multiple *.cs files. Earlier version required all code for a given type to be
defined within a single *.cs file.
For example, using Partial class modifier, we could place all the public members in a
file named MyType_Public.cs and while the private fields into MyType_Private.cs file.
once these files are compile by csc.exe, forms a single unified type
Partial Types
partial classes mean that your class definition can be split into
multiple physical files. Logically, partial classes do not make
any difference to the compiler. During compile time, it simply
groups all the various partial classes and treats them as a
single entity.
Demo
D:\prabhjot\PartialType
Partial Types
Partial Types
Partial Types
Anonymous methods
Lets Understand the Difference between old delegate and new proposed
Anonymous Delegate through Practical.
ate
eleg
d
al
orm
N
Anonymous methods
It remembered Hello
Anonymous method-end
Iterators
Demo
D:\prabhjot\hclcsharpdemo6
D:\prabhjot\csharpdemo5
Without Iterators
Without Iterators
Without Iterators
Without Iterators
With Iterators
With Iterators
Iterators-end
Conclusion: