Why Static variables?
static variable shared the value of it among all instances of the class. Changes done to static variable are visible across methods. Static variable, that means it exists exactly one place in memory for the duration of the program. Static class variables are like globals. Static variables belong to type, not to its instance. You can change the value of a static variable in any of the method of that class. Continue reading
For example, If x is a local variable, will be effectively set to null anyway when the method is exited and the value of the return value is not null.
The finally statement is executed, but the return value isn’t affected. The execution order is:
- Code before return statement is executed
- Expression in return statement is evaluated
- finally block is executed
- Result evaluated in step 2 is returned
There are technical differences between Abstract Classes and Interfaces, that being an Abstract Class can contain implementation of methods, fields, constructors, etc, while an Interface only contains method and property prototypes.
Two quick thoughts on differences between interfaces and abstract classes:
- Abstract classes desired if future expansion is likely, as an abstract class can be expanded, but an interface would have to be enhanced by addition of another interface, I2.
2. A class can inherit multiple interfaces but only one abstract class.
An Interface defines what something can do (how it behaves), and an Abstract Class defines what something is. Continue reading
What does an assembly contain?
Types of assembly?
How to register an assembly in GAC?
How C# code is converted to IL?
Why do we need two memories (Stack & Heap) ? Continue reading
An abstract class is a special kind of class that has no implementation. It cannot be instantiated. Its implementation logic is provided by the classes that derive from it. It can have both abstract as well as non-abstract methods.
It is not compulsory to have only abstract methods in an abstract class. We can also have an abstract class with only non-abstract methods.
Why do we need an Abstract Class? Continue reading
public DataTable getTop(DataTable dt, int n)
DataTable outputTable = dt.Clone();
for (int i = 0; i < n; i++)
You can use the base keyword in a constructor, to call the constructor of a class’ base class. You’d most typically do this to allow the constructor in the base class to initialize the data members that are defined in the base class. Then the constructor of the derived class can initialize its own data members.
Read more: http://csharp.2000things.com/2013/01/29/768-when-to-call-the-constructor-of-a-base-class/