Thursday, February 5, 2026

var vs dynamic

1.var

  • Type is decided at compile time

  • Strongly typed

  • Must be initialized at declaration

  • IntelliSense & compile-time checking available

Example

var x = 10;        // int
var name = "Ram"; // string

👉 If you assign a wrong type later → compile-time error


2.dynamic

  • Type is decided at runtime

  • Not strongly typed

  • No compile-time checking

  • Errors occur at runtime

Example

dynamic x = 10;
x = "Ram";        // allowed
x.DoSomething(); // runtime error if method not found

3.Key Differences (Interview Points)

Featurevardynamic
Type resolutionCompile timeRuntime
Type safetyYesNo
IntelliSenseYesNo
Error checkingCompile timeRuntime
Type change allowedNoYes

4.When to use?

  • Use var when type is obvious and you want clean code

  • Use dynamic when working with:

    • COM objects

    • Reflection

    • JSON / loosely typed data


5.Important interview one-liner

var is statically typed, dynamic is dynamically typed.


abstract class

1. What is an Abstract Class?

An abstract class is a partially implemented class.
It can have both abstract methods (no body) and normal methods (with body).

2. Key rule

  • An abstract class cannot be instantiated

  • It must be inherited by another class

3. What can an abstract class contain?

  • Abstract methods

  • Non-abstract (normal) methods

  • Fields

  • Properties

  • Constructors

4. Syntax example (interview-friendly)

abstract class Employee
{
    public abstract void Work();

    public void Login()
    {
        // common code
    }
}

class Developer : Employee
{
    public override void Work()
    {
        // implementation
    }
}

5. Method implementation rule

  • Abstract methods must be overridden in the derived class

  • Normal methods are optional to override

6. Inheritance rule

  • Supports single inheritance only

  • Multiple inheritance is not allowed with classes

7. Abstract class vs Interface (short point)

  • Abstract class → Partial abstraction

  • Interface → Complete abstraction

8. Why do we use abstract classes?

  • To share common base functionality

  • To enforce base rules with flexibility

  • When some behavior is common and some is different

9. Important interview one-liner

An abstract class provides a base class with both implemented and unimplemented methods.


Interface - An interface defines what to do, not how to do it.

1. What is an Interface?

An interface is a contract.
It defines what methods or properties a class must have, but not the implementation.

2. What can an interface contain?

  • Method declarations

  • Properties

  • Events
    👉 No method body (before C# 8.0)

3. How do we use an interface?

  • A class implements an interface

  • The class must implement all methods of the interface

4. Syntax example (interview-friendly)

interface IEmployee
{
    void Work();
}

class Developer : IEmployee
{
    public void Work()
    {
        // implementation
    }
}

5. Multiple inheritance support

  • C# does not support multiple inheritance with classes

  • But a class can implement multiple interfaces

class MyClass : IInterface1, IInterface2
{
}

6. Interface vs Abstract Class (short point)

  • Interface → 100% abstraction

  • Abstract class → Partial abstraction

7. Why do we use interfaces?

  • Loose coupling

  • Dependency Injection

  • Multiple inheritance

  • Better maintainability and testability

8. Important interview one-liner

An interface defines what to do, not how to do it.


How to Find Repeated Values in Excel Using COUNTIF

To identify repeated values in Excel,

after adding a new column for count,

after typing =COUNTIF(, come to the left arrow and move to the required column. After that, press Ctrl + Shift + End to go till the end. Then, put a comma. Next, press Ctrl + Shift + Up Arrow to come to the beginning of the column. After coming there, click Enter, then the result will come. If you drag the result, the output will come for all columns.

=COUNTIF(A2:A248,A2) - example