Saturday, October 17, 2015

Constructors and Destructors

Constructors:
1. Constructor is a special method of a class which will invoke automatically whenever instance or object of class is created.
2. It can't return any value
3. C# supports overloading of constructors
4. You can always make a call to one constructor from within another.
5. There can be only one static constructor in the class.
6. The static constructor should be without parameters and  it can only access the static members of the class.
7. There should be no access modifier in static constructor definition.
8. In inheritance base class constructor get called first.
9. It is mandatory to have the constructor in the class.
10. In case if we do not write constructor, the compiler will try to supply the no parameter constructor for your class.
11. We can neither create the object of the class, nor can we inherit the class with only private constructors.
12. We access static members from the non-static (normal) constructors,there is no such restriction on non-static constructors. But there is one on static constructors that it can access only static members.

Destructors:
1. A destructor is a member that implements the actions required to destruct an instance of a class.
2. A class can only have one destructor.
3. Destructors cannot be inherited or overloaded.
4. Destructors cannot be called. They are invoked automatically. 
5. A destructor does not take modifiers or have parameters.

Tuesday, December 16, 2014

Compare two dates in javascript



if (new Date(First_date) > new Date(SecondDate)) {
                       

//compare end <=, not >=
    //your code here


                     }

Monday, July 21, 2014

Sort in DataTable in C#



  DataView dv = dt.DefaultView;
            dv.Sort = "Date asc";
            DataTable sortedDT = dv.ToTable();

Thursday, June 19, 2014

Drop FOREIGN KEY constraint from all table of database

while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE='FOREIGN KEY'))
begin
       declare @sql nvarchar(2000)
       SELECT TOP 1 @sql=('ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME
       + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']')
       FROM information_schema.table_constraints
       WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
       exec (@sql)
end



Wednesday, June 4, 2014

Get week start date and week end date of a month in SQL server



#First week of particular month will be start from 1st day of month and last week of month will be end at month end date    

    with C(i) as
              ( select CONVERT(VARCHAR(10),CAST(@monthStart as datetime),111) i
                UNION ALL
                select CONVERT(VARCHAR(10),DATEADD (day,1,i),111) i from C
                     where DATEADD (day,1,i)
                             <DATEADD(month,1,@monthStart)
              ), C1 as
              (
              select DATEPART(WEEK,i)-DATEPART(WEEK,@monthStart)+1 WeekOfMonth,i from C
              )
              select WeekOfMonth,min(i) StartDate, max(i) EndDate from C1 group by WeekOfMonth