Monday, May 23, 2016

Interface C#

Interface 

    interface IBankCustomer
    {
        void DepositMoney();
        void WithdrawMoney();
    }

    public class Demo : IBankCustomer
    {
        public void DepositMoney()
        {
            Console.WriteLine("Deposit Money");
        }

        public void WithdrawMoney()
        {
            Console.WriteLine("Withdraw Money");
        }

        public static void Main()
        {
            Demo DemoObject = new Demo();
            DemoObject.DepositMoney();
            DemoObject.WithdrawMoney();
        }
    }

  • Interface No need access modifiers, default is public.
  • Interface methods only header, no body.
  • Interface No Field.
  • Interface No Constructor.
  • Interface can inherit other interface.
  • Child Class must implement all the Interface method.
  • Child Class can inherit mutiple Interface.

Different Interface and abstract Class

1.A class cannot inherit more than one class (class DerivedClass : BaseClass1, BaseClass2),
interface can (public class Demo : Interface1, Interface2)

2. Abstract class can have abstract or non abstract method;

Thursday, May 5, 2016

EXEC Query

DECLARE @EndDate VARCHAR(10);
DECLARE @SQL VARCHAR(5000);
DECLARE @LastDate VARCHAR(10);
DECLARE @StartDate VARCHAR(10);
DECLARE @StartYear VARCHAR(4);
DECLARE @StartMonth VARCHAR(2);

SET @StartDate = CONVERT(VARCHAR(20),DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) -1, 0),23);
SET @EndDate = CONVERT(VARCHAR(20),DATEADD(MONTH,1,@StartDate),23);
SET @LastDate = CONVERT(VARCHAR(20),DATEADD(Day,-1,@EndDate),23);
SET @StartYear = CONVERT(VARCHAR(4),datepart(yyyy,@StartDate));

SET @StartMonth = CONVERT(VARCHAR(2),datepart(mm,@StartDate));

Set @SQL 'Select *,date as ''Trans Date'' From DBYear'+ @StartYear  +'.dbo.Table WHERE TransDate BETWEEN '''+ @StartDate + ''' AND '''+ @EndDate + '''; 
exec(@SQL)
select(@SQL)