Posts

Showing posts with the label C#

Reflection In C#

Image
Reflection                 This language feature allows you to inspect the assemblies’ metadata (information of types). Use of Reflection 1.        Late binding 2.        Allow to inspect the content of assembly How to use Reflection public class Program     {         static void Main( string [] args)         {             Type tp = Type .GetType( "ConsoleApplication1.Calculator" );             PropertyInfo [] pInfo = tp.GetProperties();              MethodInfo [] minfo = tp.GetMethods();             //Create Instance ...

Attributes In C#

Image
Attributes – Used to provide the information to compiler about the behavior of class/assemblies and this information can be used by the reflection. Example 1.        Obsolete 2.        WebMethod 3.        Serializable How to use Obsolete Attribute class Program     {         int result = new Calculator ().AddTwoNumbers(1,2);     }         public class Calculator     {         [ Obsolete ( "This method is obsolete, Use new method AddNumbers(List )" )]         public int AddTwoNumbers( int num1, int num2)         {             return num1...

Access Modifier In C#

Access Modifier ·          Public - Access in assembly as well as in reference. Default public access modifier enum, Interface ·          Private - Access within the scope of curly braces ·          Protected - Access in base and derived class ·          Internal - Access within the assembly and within the program that contains its declaration. ·          Protected Internal - Can access anywhere in the same assembly   and inherited class in another assembly. public class Class : Class1     {         public void Method1( int num1)         {             //Public Variable //Accessable in derived class    ...

Overloading In C#

Overloading - When the derived class methods uses the same name, arguments and return type as a method in base class. Function must be differ by the arity (Different number of argument) and datatype. public class Class : Class1     {         public void Method1( int num1)         {         }     }     public class Class1     {         public void Method1()         {         }     } x

Types of Constructor in C#

Constructor - Constructor is special kind of methods used for initialization of a class. Types of Constructors                 Default – Without having any parameter                 publicstring fName; public clsConnect()         {             fName = "First Name" ;         }                 Parameterized – Constructor at least one parameter                 publicstring fName; public clsConnect( string sFName)         {             fName = sFName...

Sealed Keyword in C#

Image
Sealed Class – if this keyword is used on a class then it will not allow to inheritance that class and if it is used on method then it will restrict the override of that method. Sealed Method - This keyword is basically used to restrict a class for inheritance and  preventing the inheritance  Cannot be inherited

Delegates in C#

Delegates – it’s a type that holds the reference of method in an object. It’s also called type safe (It ensure that operation is working on right kind of data) function pointer. Adv –    Encapsulating the method call from caller                 Effective use of delegate improve the performance                 Use to call method asynchronously.                 Declare Delegate ->Public Delegate int delegate_name(Param optional)                 Multicast Delegate – holds the reference of more than one method. Must contain the methods return void. How to use                 Single Delegate ...