0% found this document useful (0 votes)
12 views3 pages

C# OOP, React, SQL, and Coding Questions

Uploaded by

kumar mrinal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

C# OOP, React, SQL, and Coding Questions

Uploaded by

kumar mrinal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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(![Link](n))
name = n;
}
public string GetName() {
return name;
}
}

2. Inheritance:
- One class derives from another.

Example:
class Animal {
public void MakeSound() {
[Link]("Sound");
}
}

class Dog : Animal {


public void Bark() {
[Link]("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() {
[Link]("Drawing shape");
Interview Questions and Examples
}
}
class Circle : Shape {
public override void Draw() {
[Link]("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() {
[Link]("Car started");
}
}

2. Advanced React Interview Questions

1. Difference between useEffect and useLayoutEffect?


2. How does useCallback improve performance?
3. What is [Link] 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 [Link], [Link]
FROM Employees E
INNER JOIN Departments D ON [Link] = [Link];

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 = [Link] - 1; i >= 0; i--) {
result += input[i];
}
return result;
}

2. Check Palindrome:
bool IsPalindrome(string s) {
int start = 0, end = [Link] - 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 < [Link]; i++) {
for(int j = i+1; j < [Link]; j++) {
if(arr[i] == arr[j]) {
[Link](arr[i]);
break;
}
}
}

4. Find missing number:


int[] arr = {1,2,4,5};
int n = 5, sum = 0;
for(int i = 0; i < [Link]; i++) sum += arr[i];
int expected = n * (n + 1) / 2;
int missing = expected - sum;
[Link]("Missing: " + missing);

Common questions

Powered by AI

`useEffect` is suitable for running side effects that do not require a synchronous layout update, such as data fetching and subscriptions, as it runs asynchronously after the paint. This improves performance by preventing the blocking of visual updates. Conversely, `useLayoutEffect` is useful for reading layout attributes or when precise synchronization with the DOM is needed, operating synchronously after all DOM mutations but before the paint, making it more suited for animations and measuring DOM properties changes .

Reverse engineering a string is crucial for algorithms that require manipulations like palindrome checks or data decoding. In C#, this can be achieved manually by iterating through the string in reverse order and appending each character to a result variable, as demonstrated in `ReverseString`, which iterates from the last character to the first, building a reversed string without using built-in reverse methods .

The virtual DOM is a lightweight JavaScript representation of the actual DOM. React uses this to optimize performance by selectively updating only parts of the DOM that have changed. During reconciliation, React compares the new virtual DOM with the previous version to identify differences. Instead of updating the entire DOM tree, React applies changes only to the components that need it, thereby minimizing actual DOM manipulations and enhancing performance through reduced computational cost and improved speed of operations .

Inheritance allows a class to derive properties and behavior from another class, enabling code reusability. For instance, `Dog` inherits from `Animal`, gaining its `MakeSound` method while adding its own `Bark` method. Polymorphism, on the other hand, refers to the ability of different classes to be treated as instances of the same class through interfaces or base classes, with the same method taking multiple forms. It includes method overloading (compile time) and overriding (runtime), as seen in `MathUtil` for overloading and `Shape` for overriding with `Circle` providing a specific `Draw` method .

Custom hooks in React allow the extraction and reuse of logic that involves the use of stateful logic or lifecycle features. They can enhance component functionality by enabling the sharing of behavior between components without re-implementing logic, thereby promoting DRY (Don't Repeat Yourself) principles. For instance, a custom hook for fetching data can be used across multiple components, encapsulating the logic in a single, reusable location .

React manages global state using strategies like Redux and Context API. Redux offers a centralized store and immutable state updates, which improve scalability and predictability, but adds complexity and boilerplate in setup. The Context API is simpler, leveraging React's built-in context to propagate state changes, which is more suitable for less complex state needs; however, it can become cumbersome and less performant as the application scales, due to the tendency to re-render more components than necessary .

SQL JOIN operations link tables based on related columns. `INNER JOIN`, the most common, returns records only when there are matching values in both tables. This is optimal for queries requiring only related entries. Conversely, `FULL JOIN` returns all records when there is a match in either left or right table records, and fills gaps with NULLs, making it more suitable for comprehensive data overviews where all possible records and their relationships, including unmatched ones, need visibility .

Encapsulation improves software design by restricting direct access to some of the object's components and maintaining a boundary between an object's data and its usage, enhancing modularity and preventing unintended interference. This is achieved by using private variables and providing public methods to access or modify these variables. For example, in the C# class `Person`, the `name` variable is private and can only be accessed through the `SetName` and `GetName` methods. This ensures that `name` is only set when non-null or non-empty inputs are provided, safeguarding the integrity of the data .

Abstraction could significantly benefit the maintenance of driver interfaces in vehicle control systems by hiding the implementation details within abstract classes or interfaces such as `Vehicle`. This allows for a uniform method (e.g., `Start`) across various derived classes like `Car` or `Truck`, enabling changes to implementation with minimal effect on the rest of the system and improving maintainability by emphasizing the essential characteristics rather than specific implementation details .

React.memo enhances performance by memoizing functional components, meaning that React will skip rendering the component and reuse the last rendered output when its props have not changed. This is particularly useful for optimizing functional components that render the same results given the same props, preventing unnecessary re-renders and thus improving performance in complex, large applications .

You might also like