Friday, December 14, 2012

Different types of Access Modifiers

Posted by Rahul Kharde at 2:50 AM

Access Modifier
Description (who can access)

private
Private members are accessible only within the body of the class or the struct in which they are declared.

protected
A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member.

internal
Internal members are accessible only within files in the same assembly

protected internal
Either code from derived type or code in the same assembly. Combination of protected OR internal.

public
There are no restrictions on accessing public members.

Read More »

What is Abstract Class?

0 comments Posted by Rahul Kharde at 12:44 AM

  • Abstract Class mostly used as a base class.
  • Abstract class is a class that cannot be instantiated, it exists extensively for inheritance and it must be inherited.
  • An Abstract Method of an Abstract Class must be overridden.
  • Abstract classes are classes that contain one or more abstract methods (methods without implementation).
  • Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete, it may contain only definition of the properties or methods and derived classes that inherit this implements it's properties or methods.
  • There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as base-class.
  • An abstract method is a method that is declared, but doesn't contain implementation (like method declaration in the interface).
Read More »

Wednesday, December 05, 2012

‘Base’ in C#

0 comments Posted by Rahul Kharde at 11:16 PM

The base keyword is used to access members of the base class from within a derived class
Base is used in constructors. A derived class constructor is required to call the constructor from its base class. When the default constructor isn't present, the custom base constructor can, with base, be referenced. Base class has been overridden by another method.

Example  1

    public class ClassA
    {
        public virtual void Method1()
        {
            Console.WriteLine("ClassA");
        }
    }
    class ClassB : ClassA
    {
        public override void Method1()
        {
            base.Method1();
            Console.WriteLine("ClassB");
        }
    }
    class ClassC : ClassB
    {
        public override void Method1()
        {
            base.Method1();
            Console.WriteLine("ClassC");
        }
    }
   class Program
    {
        static void Main()
        {
            ClassC obj = new ClassC();
            obj.Method1();
        }
    }
Output
ClassA
ClassB
ClassC
Here, ClassA is base Class and ClassB and ClassC Are Drived classes and have a Method named Method1


Example 2

  public class ClassA
    {
        public ClassA()
        {
            Console.WriteLine ("In Base ClassA()");
        }

        public ClassA(int i)
        {
            Console.WriteLine ("In Base ClassA(i)");
        }
    }

    public class ClassB : ClassA
    {
        public ClassB() : base()
        {

        }
        public ClassB(int i) : base(i)
        {
        }
    }

    class Program
    {
        static void Main()
        {
            ClassB objB = new ClassB();
            ClassB ObjB1 = new ClassB(1);
        }
    }
Output

In Base ClassA()
In Base ClassA(i)
Read More »

Monday, December 03, 2012

Combine multiple rows into a comma separated Column in SQL-SERVER -2008

0 comments Posted by Rahul Kharde at 12:25 AM

If we required comma separated values form one to column in multiple rows.

Example
 

CREATE TABLE EMP
(
      EID       INT IDENTITY,
      ENAME   VARCHAR(100),
      DEPT    VARCHAR(100)
)

INSERT INTO EMP(ENAME,DEPT)
                  VALUES('ABC','SALE'),
                        ('PQR','IT'),
                        ('XYZ','HR'),
                        ('MNL','ADMIN')


DECLARE @DEPT VARCHAR(255)

SELECT @DEPT=COALESCE(@DEPT + ', ', '') + CAST(DEPT AS VARCHAR(100))
FROM EMP


SELECT @DEPT as 'Department'  


Output

Department
-----------------
SALE, IT, HR, ADMIN
Read More »
 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top