Posts

C# Interface

Image
Interface is like a class that contains only a definition of methods, events and properties. Interface is like a class that cannot be instantiated, interface define the abilities unlike a class that defines what an object is.  The purpose of an interface is to define a set of requirements that a class must implement. A class can inherit from multiple interfaces, and an interface can be implemented by many classes.   Interface members are automatically public, no access modifiers are allowed on interface members and they can also not be static. An interface cannot include an instance constructor because an interface cannot be instantiated. An interface cannot inherit from a class. An interface cannot contain fields and constants. An interface can be declared by attaching an interface keyword before the name of the interface and that is it, by convention I is used in naming an interface. interface IShapeComputer { string ShapeName { get; set; } ...

C# class

Image
A class is used to model an object, it defines what the object is and how it is going to behave. A class is like a blueprint, from a single class we can create as many objects as we want at runtime, creating an object from a class is called instantiation. A class is a reference type meaning that when an object of the class is instantiated and the instantiated object is assigned to some variable, the variable which the instantiated object is assigned to holds only the memory location of the instantiated object. If the instantiated object is assigned to multiple variables, all the variable refers to the memory address of the instantiated object, changes made to one variable are reflected in the other variables. When you declare a variable of a class type without instantiation, the created variable holds a null value until you assign to it an object that is compatible with it. eg. SomeClass someclass; // someclass is a variable of type SomeClass and it has a value of null So...