Total Pageviews

Wednesday, May 12, 2010

What is Boxing & Unboxing in C#?

Boxing means converting Value type to a Reference type.

Ex :

int i=100;

object obj=(object) i;

Unboxing means converting Reference type to a Value type.

Ex:

object obj=100;

int i=(int)obj;

Usage of SQL SELECT statements

Followings are some examples of using SELECT statement. My table name tblTest. Followings are columns. (TestID, TestName, TestDate, TestCity )


1) Select * from tblTest (Returns all columns/Rows)

2) Select * from tblTest Where TestID=2 (Returns the row/s which TestID has value 2)

3) Select * from tblTest where TestID Between 10 and 20 (Return all rows between 10 and 20, this result includes 10 and 20)

4) Select * from tblTest Where TestCity in ('New York','Washington','California') (Returns all rows which city is NewYork, Washington, california)

5) Select * from tblTest Where TestName Like 'A%' (Return all rows where the name starts letter A)

6) Select * from tblTest Where TestName Like '%A' (Return all rows where the name ends letter A)

7) Select * from tblTest Where TestName Like '[ABC]%' (Return all rows of name start with A / B / C)

8) Select * from tblTest Where TestName Like '[^ABC]%' (Return all rows of name not start with A and B and C)

9) Select (TestName+space(1)+TestCity) as Address from tblTest (Returns single column address, name and city added together with a space)

10) Select * from tblTest Where TestName IS NULL (Return all rows which TestNane has null values)

11) Select * from tblTest Where TestName IS NOT NULL (Return all rows which TestNane has not null values)

12) Select * from tblTest Order By TestID Desc (Sort the result set descending order, Asc or not using any sort Ascending order)

13) Select 'Visual Studio' as IDE, '2010' as Version (Creating memory resident result set with two columns[IDE and Version])

14) Select Distinct TestID from tblTest (Returns unique rows based on TestID)

15) Select Top 10 * from tblTest (Return 10 customers randomly)

16) Select getdate() (Shows the current date)

17) Select db_name() (shows the database name which you are working on)

18) Select @@Servername (Shows name of the server)

19) Select serverproperty ('Edition') (You can pass following ServerName, Edition, EngineEdition, ProductLevel to get current information about the server)

20) Select user_name() (Get current user)

21) Select * into #test from tblTest (Create temporary table #test and insert all records from tblTest)

22) Select Max(TestID) from tblTest (Returns Maximum TestID from tblTest)

23) Select * from tblTest Compute Max(TestID) (Returns two result sets - getting all rows and maximum value of TestID)

24) Select FirstName, LastName, Salary, DOB,

Case Gender
When 'M' Then 'Male'
When 'F' Then 'Female'
End
From Employees

(This Change Gender fields as if M then prints Male and if F then prints Female)

VS Shortcuts

Followings are some useful shortcuts for coders:

Copy a single line - CTRL+C [Move the insertion point at the begin or end and press space bar, then press the shortcut key combination]

Cut a single line - CTRL+X [Move the insertion point at the begin or end and press space bar, then press the shortcut key combination]

Comment a line - CTRL+K, CTRL+C [Keep the insertion point any where on line and press ]

UnComment a line - CTRL+K, CTRL+U [Keep the insertion point any where on line and press ]

Put/Remove a break point - F9

Remove all break points as once - CTRL+SHFT+F9

Expand/Collapse a region- CTRL+M, CTRL+M

Intellisense - Ctrl+Space [Press CTRL again make the drop down transparent]

Build Solution - Ctrl+Shft+B

Expand All regions - Ctrl+M+P

Collapse All regions - Ctrl+M+O

New Break Point - Ctrl+B