Friday, December 3, 2010

default access modifier in c#

internal


 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.

Reference:
http://msdn.microsoft.com/en-us/library/ms173121.aspx

MVC pattern


Reference:

keys

Primary key
  • an attribute/column which uniquely identifies a record
  • primary key can be column/combination of columns
  • primary key cannot have null values

Candidate key

  • Candidate key is a column which is not a primary key, but it can qualify as a primary key
  • there can be multiple candidate key in one table

alternate key

  • any of the candidate key that is not part of primary key

Tuesday, November 30, 2010

yeild

yeild is the income return of an investment. (in finance)

in C#,

  • yeild keyword use inside iterator block.
  • it indicates the end of iterator block

restriction
  • cannot use with unsafe block
  • parameter to method cannot be out/ref 
  • cannot appear in anonymous method

Thursday, November 25, 2010

correlated sub query

It is a query nested inside another query.

http://en.wikipedia.org/wiki/Correlated_subquery


Scenario: Write a query to select all employees from eastern region. DB diagram follows:




--select all employees from Eastern region
select * from employees where EmployeeID in
(
    -- select all Employees under territory which comes under Eastern region
    select EmployeeID from employeeterritories where TerritoryID in
    (
        --select all territory for Easter region (RegionID = 1)
        select TerritoryID from territories where RegionID = 1
     )
 )

Generalization & Realization

In UML modeling,

Generalization is inheritance.
Realization is implemeting interface.


In UML modeling, generalization relationship is a relationship in which one entity is based on another entity.

Realized - is a related to interface. Interface should implement in class, in UML terms it is called as realized. To realize an interface, a class should implement all its properites and methods

Reference:

1. Generalization:

http://publib.boulder.ibm.com/infocenter/rsmhelp/v7r0m0/index.jsp?topic=/com.ibm.xtools.modeler.doc/topics/creal.html

2. Realization:

http://publib.boulder.ibm.com/infocenter/rsmhelp/v7r0m0/index.jsp?topic=/com.ibm.xtools.modeler.doc/topics/creal.html

Monday, November 22, 2010

upcasting and downcasting

upcasting - is possible, its implicit coversion and is safe. (ie,  A aa=new B() - is upcasting. Here were are converting from Type B to Type A. It is possible, because A is the base class. And all the base class methods and properties will be available in object aa). Its called upcasting because we more moving up the object hierarchy.

downcasting - is explicit conversion and is unsafe. you will have to be very careful while downcasting types.  Its called downcasting because we are moving down the object hierarchy.


(with sample: class A, class A:B, class C:B)

Class A
{
}

Class B:A
{
}

Class C:B
{
}


Question:
A aa=new B();       // is this possible? Ans:
A aa=new C();       // is this possible? Ans:
B bb=new A();       // is this possible? Ans:
B bb=(B)new A();  // is this possible? Ans:


Solution

A aa = new B(); // is possible.

Implicit conversion from Type B to Type A is possible. Because Type A is the base class and Type B is derived from Type A.

//B bb = new A();   //compile Error : Cannot implicitly convert type 'A' to 'B'. An explicit conversion exists


//B bb = (B) new A(); //runtime Error : System.InvalidCastException - Unable to cast object of type 'A' to type 'B'



Hint:

Car c=new BMW();   //possible
BMW b=new Car();  //not possible, compile error - implicit conversion not possible from type Car to BMW
BMW_E_Series be=new Car(); //not possible, compile error
BMW_E_Series be= (BMW_E_Series) new Car(); //runtime error, explicit conversion not possible


Reference:

http://www.c-sharpcorner.com/UploadFile/pcurnow/polymorphcasting06222007131659PM/polymorphcasting.aspx