Skip to main content

Posts

Showing posts from December, 2012

Different types of Access Modifiers

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.

What is Abstract Class?

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).

‘Base’ in C#

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

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

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