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

Tuesday, November 16, 2010

Difference between new Operator and Modifier

• new operator Used to create objects on the heap and invoke constructors.

• new modifier Used to hide an inherited member from a base class member.

Example for new modifier:


Tuesday, November 9, 2010

tic tac toe

Create design for tic tac toe game. Draw use case diagram, class diagram & write the pseudo code of the logic.

Nested class

namespace NestedClass
{
class Program
{
static void Main(string[] args)
{
A a = new A();

A.AA aa = new A.AA();

}
}

public class A
{
public class AA
{
public int i = 10;
A x = new A();
A.AA xx = new AA();
}
}
}

Application state in ASP.NET

  • Application is a server side state mechanism in ASP.NET.
  • It is a global way to store data in ASP.NET applications.
  • It stores as key/value pair.
  • application state is an instance of HttpApplicationState class
http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx

Different state management techniques in ASP.NET

client side state management techniques:

  1. ViewState
  2. ControlState
  3. Cookies
  4. Hidden fields

Server side state management techniques

  1. Session
  2. Application
Reference: http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx

String is a reference type. In the below code, what would be the output?

class Program
{
static void Main(string[] args)
{
string s = "abc";
CallMethod(s);
Console.WriteLine(s);
Console.Read();

}
static void CallMethod(string s)
{
s = "xyz";
}
}

Output: abc

difference between server.transfer and response.redirect

Both Respone.Redirect and Server.Transfer open up another page, but the interaction between client(browser) and server(asp.net) differs in each situation.

Resonse.Redirect simply tell the browser to visit another page.
Its the reponsibility of the browser to open up the another page.
External sites can be opened.

Server.Transfer works for only sites which runs on the server.
External sites cannot be opened.
Sharing states between pages is much easier using Server.Transfer.
Server.Transfer keeps the URL the same. This may lead to confusion.