Interview Questions and Examples
1. OOPs Concepts in C#
1. Encapsulation:
- Wrapping data and logic inside a class using private variables and public methods.
Example:
class Person {
private string name;
public void SetName(string n) {
if(!string.IsNullOrEmpty(n))
name = n;
}
public string GetName() {
return name;
}
}
2. Inheritance:
- One class derives from another.
Example:
class Animal {
public void MakeSound() {
Console.WriteLine("Sound");
}
}
class Dog : Animal {
public void Bark() {
Console.WriteLine("Bark");
}
}
3. Polymorphism:
- Same method behaves differently (Overloading & Overriding).
Compile Time (Overloading):
class MathUtil {
public int Add(int a, int b) {
return a + b;
}
public int Add(int a, int b, int c) {
return a + b + c;
}
}
Run Time (Overriding):
class Shape {
public virtual void Draw() {
Console.WriteLine("Drawing shape");
Interview Questions and Examples
}
}
class Circle : Shape {
public override void Draw() {
Console.WriteLine("Drawing circle");
}
}
4. Abstraction:
- Hiding implementation using abstract classes/interfaces.
Example:
abstract class Vehicle {
public abstract void Start();
}
class Car : Vehicle {
public override void Start() {
Console.WriteLine("Car started");
}
}
2. Advanced React Interview Questions
1. Difference between useEffect and useLayoutEffect?
2. How does useCallback improve performance?
3. What is React.memo and when should you use it?
4. Explain virtual DOM and reconciliation.
5. How do you manage global state (Redux, Context)?
6. What are custom hooks?
7. How does React handle performance optimization?
8. What is Suspense and lazy loading in React?
3. SQL Joins
1. INNER JOIN: Only matching rows from both tables.
2. LEFT JOIN: All records from left, matching from right.
3. RIGHT JOIN: All records from right, matching from left.
4. FULL JOIN: All records from both tables.
Example:
SELECT E.Name, D.DeptName
FROM Employees E
INNER JOIN Departments D ON E.DeptId = D.Id;
4. Array & String Problems (C# Custom Logic)
1. Reverse a string without using Reverse:
string ReverseString(string input) {
Interview Questions and Examples
string result = "";
for(int i = input.Length - 1; i >= 0; i--) {
result += input[i];
}
return result;
}
2. Check Palindrome:
bool IsPalindrome(string s) {
int start = 0, end = s.Length - 1;
while(start < end) {
if(s[start] != s[end])
return false;
start++; end--;
}
return true;
}
3. Find duplicate elements in array:
int[] arr = {1,2,3,2,1};
for(int i = 0; i < arr.Length; i++) {
for(int j = i+1; j < arr.Length; j++) {
if(arr[i] == arr[j]) {
Console.WriteLine(arr[i]);
break;
}
}
}
4. Find missing number:
int[] arr = {1,2,4,5};
int n = 5, sum = 0;
for(int i = 0; i < arr.Length; i++) sum += arr[i];
int expected = n * (n + 1) / 2;
int missing = expected - sum;
Console.WriteLine("Missing: " + missing);