Components of CLR
using System;
class Hello {
static void Main( ) {
Console.WriteLine("Hello world");
Console.ReadLine(); // Hit enter to finish
}
}
Interfaces example
An interface defines a contract
An interface is a type
Contain definitions for methods,
public interface IDelete {
properties,
void Delete();
}
public class TextBox : IDelete { Interfaces provide no implementation
When a class or implements an
public void Delete() { ... }
interface it must provide the
} implementations
public class ImageBox : IDelete {
public void Delete() { ... }
}
OOP Object oriented programming–
Encapsulation
These variables and methods are accessible from within the class,
but not accessible outside it.
Public
Accessible anywhere
Protected
Accessible within its class and by derived class instances
Private
Accessible only within the body of the class
(Or anywhere if you use reflection)
Internal
Intuitively, accessible only within this program (more
specific definition here)
The default, but you should generally pick public or private
instead
Abstraction
Members marked as abstract must be implemented by non-abstract classes that derive from
the abstract class.
Dynamic Polymorphism
C# allows you to create abstract classes that are used to provide
partial class implementation of an interface. Implementation is
completed when a derived class inherits from it. Abstract classes
contain abstract methods, which are implemented by the derived
class.
Static Polymorphism
The mechanism of linking a function with an object during
compile time is called early binding. It is also called static
binding. C# provides two techniques to implement static
polymorphism. They are −
•Function overloading
•Operator overloading
class Printdata {
void print(int i) { Console.WriteLine("Printing int: {0}", i ); }
void print(double f) { Console.WriteLine("Printing float: {0}" , f);
} void print(string s) { Console.WriteLine("Printing string: {0}",
s); }
}
Dynamic Polymorphism