Monthly Archives: September 2013

Update statment using Joins


update t1
set t1.totalHrsWorked=cast(DATEDIFF(MINUTE , t2.startDate, t2.endDate) *0.0166667 AS decimal(10,2))
from Table1 t1
inner join Table2 t2
on t1.Id = t2.Id
where t1.Id between 1 and 100

Default Access Modifiers in C#


Non Nested type 

                    | Default   | Permitted declared accessibilities
------------------------------------------------------------------
namespace            | public    | none (always implicitly public)

enum                 | public    | none (always implicitly public)

interface            | internal  | public, internal

class                | internal  | public, internal

struct               | internal  | public, internal

delegate             | internal  | public, internal

Nested Type
                     | Default   | Permitted declared accessibilities
------------------------------------------------------------------
namespace            | public    | none (always implicitly public)

enum                 | public    | none (always implicitly public)

interface            | public    | none

class                | private   | All¹

struct               | private   | public, internal, private²

delegate             | private   | All¹

constructor          | protected | All¹

interface member     | public    | none (always implicitly public)

method               | private   | All¹

field                | private   | All¹

user-defined operator| none      | public (must be declared public)

¹ All === public, protected, internal, private, protected internal

² structs cannot inherit from structs or classes (although they can, interfaces), hence protected is not a valid modifier

 

Nullable type


Normally we are expert in using value types like int, bool, decimal types.But those types dont have null values by default. Suppouse if you want to insert null value to database for above value types.

Example:

Boolean variable can have two values: true and false. There is no value that signifies “undefined” (null). Suppose you want to insert null value in the database column for Boolean value then there is no direct option to store null value since i have only two values: true and false.

bool boolIsNull= null; // Not Possible

To handle this kind of values .NET give us a very useful tool to for this: nullable types.

Nullable<T> //Nullable<int> or Nullable<decimal>
bool? boolIsNull= null; //Correct

 

Ref: http://www.codeproject.com/Articles/275471/Nullable-Types-in-Csharp-Net