Thursday, 24 May 2012

Value types and Reference types

Value types and Reference types

Here are the key points:
■ The value of a reference type expression (a variable for example) is a reference,
not an object.
■ References are like URLs—they are small pieces of data that let you access the
real information.
■ The value of a value type expression is the actual data.
■ There are times when value types are more efficient than reference types, and
vice versa.
■ Reference type objects are always on the heap, but value type values can be on
either the stack or the heap, depending on context.
■ When a reference type is used as a method parameter, by default the parameter
is passed by value—but the value itself is a reference.
■ Value type values are boxed when reference type behavior is needed; unboxing
is the reverse process.


Post By : Dipen Shah
Blog By : Dipen Shah

Boxing and Unboxing - c#

What is concept of Boxing and Unboxing ?
Boxing and unboxing act like bridges between value type and reference types. When we convert
value type to a reference type it’s termed as boxing. Unboxing is just vice-versa. When an object
box is cast back to its original value type, the value is copied out of the box and into the
appropriate storage location.

Example: of boxing and unboxing where integer data type are converted in to object
and then vice versa.
int i = 1;
object obj = i; // boxing
int j = (int) obj; // unboxing


Post By : Urvish Patel
Blog By : Dipen Shah

Tuesday, 22 May 2012

What is shadowing?

When two elements in a program have same name, one of them can hide and shadow the other
one. So in such cases the element, which shadowed the main element, is referenced.
Below is a sample code, there are two classes “Parent” and “ShadowedParent”. In
“Parent”, there is a variable “x” which is a integer. “ShadowedParent” overrides
“Parent” and shadows the “x” variable to a string.

Example:

Public Class Parent
Public x As Integer
End Class
Public Class ShadowedParent
Inherits Parent
Public Shadows x As String
End Class

Difference between Shadowing and Overriding:
• Overriding redefines only the implementation while shadowing redefines the whole
element.
• In overriding derived classes can refer the parent class element by using “ME” keyword,
but in shadowing you can access it by “MYBASE”.

Post By : Urvish Patel
Blog By : Dipen Shah
Learn New...

Retrieving the content of a GridView cell.

 You often need to retrieve the gridview cell content and you write the long code in your code behind.

Below mentioned script are used to retrieve the cell content of gridview on click.

<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#<%=GridView.ClientID%> tr").filter(":not(:has(table, th))").click(function(e)
{
var $cell = $(e.target).closest("td"); $("#<%=GridView1.ClientID%> td"). removeClass("highlight"); $cell.addClass("highlight"); $("#message").text('You have selected: ' + $cell. text());
});
});
</script>

Post By : Dipen Shah
Blog By : Dipen Shah
Stay Connected...

Monday, 21 May 2012

Delete Duplicate Data - SQL

Delete Duplicate Data without Using primary key and Identity key:

Example:
Id
Name
1
Test
1
Test
1
Test

USE Test
Go
WITH Duplicates AS
(
    SELECT Name,Id,
      ROW_NUMBER() OVER (PARTITION BY Id,Name ORDER BY Id) AS 'RowNum'
    FROM dbo.TestDuplicates  
     
)delete FROM Duplicates WHERE RowNum>1
SELECT * FROM dbo.TestDuplicates

After using this:

Id            Name
1              Test

Post By : Urvish Patel
Blog By : Dipen Shah
Stay Tuned...We rocked...