Professional Documents
Culture Documents
1. Encapsulation
2. Inheritance
3. Polymorphism
Encapsulation in C#:
Encapsulation is process of keeping data and methods together inside
objects. In C#, encapsulation is realized through the classes. A Class can contain
data structures and methods
public class Aperture
{
public Aperture()
{}
protected double height;
protected double width;
protected double thickness;
Other methods or objects can interact with this object through methods that have
public access modifier.
Inheritance in C#:
In a few words, Inheritance is the process of creation new classes from already
existing classes. The inheritance feature allows us to reuse some parts of
code. So, now we have some derived class that inherits base class's members.
public class Door : Aperture
{ public Door() : base()
{}
public bool isOutside = true;}
As you see to inherit one class from another, we need to write base class name
after : symbol. Next thing that was done in code Door () constructor also
inherits base class constructor. And at last we add new private field. All
members of Aperture class are also in Door class. We can inherit all the
members that has access modifier higher than protected.
Polymorphism in C#:
Polymorphism is possibility to change behavior with objects depending of object's
data type. In C# polymorphism realizes through the using of keyword virtual and
override
public virtual void Out()
{
Console.WriteLine("Aperture virtual method called");
}
//This method is defined in Aperture class.
public override void Out()
{
Console.WriteLine("Door virtual method called");
}
Now we need to re-define it in our derived Door class. The usage of virtual methods
can be clarified when we creating an instance of derived class from the base class:
Aperture ap = new Door();
ap.Out();
Virtual and Overridden Methods
Only if a method is declared virtual, derived classes can override this method if they
are explicitly declared to override the virtual base class method with the override
keyword.
using System;
namespace Polymorphism
{
class A
{
public virtual void Foo() { Console.WriteLine("A::Foo()"); }
}
class B : A
{
public override void Foo() { Console.WriteLine("B::Foo()"); }
}
class Test
{
static void Main(string[] args)
{
A a;
B b;
a = new A();
b = new B();
a.Foo(); // output --> "A::Foo()"
b.Foo(); // output --> "B::Foo()"
a = new B();
a.Foo(); // output --> "B::Foo()"
}
}
}
Method Hiding
A hiding method has to be declared using the new keyword.
using System;
namespace Polymorphism
{
class A
{
public void Foo() { Console.WriteLine("A::Foo()"); }
}
class B : A
{
public new void Foo() { Console.WriteLine("B::Foo()"); }
}
class Test
{
static void Main(string[] args)
{
A a;
B b;
a = new A();
b = new B();
a.Foo(); // output --> "A::Foo()"
b.Foo(); // output --> "B::Foo()"
a = new B();
a.Foo(); // output --> "A::Foo()"
}
}
}
Constructors
Types of Constructors
Static
Non-Static
Application Pool
Application pools isolate sites and applications to address reliability, availability,
and security issues.
- To group sites and applications that run with the same configuration settings
- To isolate sites and applications that run with unique configuration settings.
- To increase security by using a custom identity to run an application.
Integrated, if you want to use the integrated IIS and ASP.NET request-
processing pipeline.
Classic, if you want to use IIS and ASP.NET request-processing modes
separately. In classic mode, managed code is processed by using Aspnet_isapi.dll
instead of the IIS 7 integrated pipeline.
Localization
Localization is customizing data and resources for specific culture or language.
Controls
HTML controls, HTML server controls, web server controls, validation controls, and
controls created by the developer.
Custom controls are compiled controls. Custom controls can be created in one of
three ways:
- derived custom control- By deriving a new custom control from an existing
control
- composite custom control - By composing a new custom control out of two or
more existing controls
- full custom control By deriving from the base control class
UserControl
.ascx extension
There are three steps in defining and using delegates: declaration, instantiation,
invocation
In C#, delegates are multicast, which means that they can point to more than
one function at a time
Events
Partial
split the definition of a class or a struct, an interface or a method over two or more
source files.Example: When working on large projects, spreading a class over
separate files enables multiple programmers to work on it at the same time
public
The type or member can be accessed by any other code in the same assembly or another
assembly that references it.
private
The type or member can be accessed only by code in the same class or struct.
protected
The type or member can be accessed only by code in the same class or struct, or in a class
that is derived from that class.
internal
The type or member can be accessed by any code in the same assembly, but not from
another assembly.
protected internal
The type or member can be accessed by any code in the assembly in which it is declared,
or from within a derived class in another assembly. Access from another assembly must
take place within a class declaration that derives from the class in which the protected
internal element is declared, and it must take place through an instance of the derived
class type
SQL
Referential integrity is a database concept that ensures that relationships
between tables remain consistent. When one table has a foreign key to another
table, the concept of referential integrity states that you may not add a record to
the table that contains the foreign key unless there is a corresponding record in the
linked table. Example: Employees and Managers
1. We may not add a record to the Employees table unless the ManagedBy attribute
points to a valid record in the Managers table.
2. If the primary key for a record in the Managers table changes, all corresponding
records in the Employees table must be modified using a cascading update.
3. If a record in the Managers table is deleted, all corresponding records in the Employees
table must be deleted using a cascading delete.