New Features
New Features
References
• The types created for classes are called references.
• Unlike other basic types (like int, float etc. that are created in
the stack), references are created in the heap.
C# New Features • They are implicit pointers to the object created.
• The space for the object allocation is not done until runtime.
Point p1= new Point(10,20)
Miscellaneous Features
Point p2= new Point(20,30);
x=10
Objects created in the heap are y=20
p1
automatically garbage collected. So no
explicit freeing of memory is needed. x=20
p2 y=30
p1 and p2 are in stack of method in
which they are created.
[email protected] [email protected]
[email protected] [email protected]
1
10/9/2016
class Program
• Contra variance permits a method with { Covariance Contravariance
static string consoledisplay(Employee m)
parameter types that are less derived than in {
m.print();
the delegate type. return "success";
}
• In the following example, We will use the static void Main()
{
Employee (Base) and Manager (Derive) Manager e = new Manager(1, "Mohan", "Type 2");
Display d = new Display(consoledisplay);
class. Manager inherits from Employee and it }
Console.WriteLine(d(e));
[email protected] [email protected]
[email protected] [email protected]
2
10/9/2016
[email protected] [email protected]
[email protected] [email protected]
3
10/9/2016
[email protected] [email protected]
4
10/9/2016
Example Dynamic
using System;
class Program • The dynamic type enables the operations in which it
{
static void Main() occurs to bypass compile-time type checking. Instead,
{
//Omit the optional parameters. these operations are resolved at run time.
Fun();
//Omit second optional parameter. • The dynamic type simplifies access to COM APIs such
Fun(4);
//You can't omit the first but keep the second.
as the Office Automation APIs, and also to dynamic
//Fun("Dot"); APIs such as IronPython libraries, and to the HTML
//Classic calling syntax.
Fun(4, "Dotnet"); Document Object Model (DOM).
//Specify one named parameter.
Fun(name: "Ram"); • Type dynamic behaves like type object in most
//Specify both named parameters.
Fun(value: 5, name: "Hari"); circumstances. However, operations that contain
}
static void Fun(int value = 101, string name = "C#") expressions of type dynamic are not resolved or type
{
Console.WriteLine("value = {0}, name = {1}", value, name);
checked by the compiler.
}
}
[email protected] [email protected]
[email protected] [email protected]
[email protected] [email protected]
5
10/9/2016
Thanks