⚡ Angular & .NET Interview Q&A (Clean & Aligned)
1️⃣ What is the @Output Decorator in Angular?
Answer:@Output is used to send data from a child component to a parent component.
It works with EventEmitter.
Example
@Output() notify = new EventEmitter<string>();
sendData() {
this.notify.emit("Hello Parent");
}
<app-child (notify)="receiveData($event)"></app-child>
2️⃣ Difference Between Component and Service
Answer:
Component
Handles UI (HTML, CSS, TS)
Used in templates
Manages user interaction
Service
Handles business logic
Used via Dependency Injection
Reusable across components
👉 Component = UI
👉 Service = Logic
3️⃣ Order of HTTP Interceptors in Angular
Answer:
Interceptors execute in the order they are registered.
Flow:
Request → Top to Bottom
Response → Bottom to Top
Example
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: FirstInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: SecondInterceptor, multi: true }
]
👉 Request: First → Second
👉 Response: Second → First
4️⃣ Subject vs BehaviorSubject
Answer:
Subject
No initial value
Does not store last value
BehaviorSubject
Requires initial value
Stores and emits last value to new subscribers
Example
const subject = new Subject<number>();
const behavior = new BehaviorSubject<number>(0);
5️⃣ Reactive Forms Syntax
Answer:
Step 1: Import
import { FormGroup, FormControl } from '@angular/forms';
Step 2: Define Form
form = new FormGroup({
name: new FormControl(''),
email: new FormControl('')
});
Step 3: HTML
<form [formGroup]="form">
<input formControlName="name">
<input formControlName="email">
</form>
6️⃣ Check if Two Strings Are Same (Anagram)
Answer:
string s1 = "ababc";
string s2 = "bcbac";
char[] arr1 = s1.ToCharArray();
char[] arr2 = s2.ToCharArray();
Array.Sort(arr1);
Array.Sort(arr2);
if (new string(arr1) == new string(arr2))
Console.WriteLine("Strings are same (Anagram)");
else
Console.WriteLine("Strings are not same");
👉 Logic: Sort + Compare
7️⃣ Delegates in .NET
Answer:
A delegate is a type-safe function pointer that holds reference to a method.
Example
public delegate void MyDelegate(string msg);
class Program
{
static void Show(string message)
{
Console.WriteLine(message);
}
static void Main()
{
MyDelegate del = Show;
del("Hello");
}
}
8️⃣ ADO.NET vs EF Core
Answer:
ADO.NET
Uses SQL queries
More control
Faster but more code
EF Core
Uses LINQ
ORM-based
Faster development
👉 ADO.NET = Control + Performance
👉 EF Core = Simplicity + Productivity
9️⃣ .NET Framework vs .NET Core
Answer:
.NET Framework
Windows only
Older architecture
.NET Core / .NET
Cross-platform
High performance
Open-source
👉 .NET Core is preferred for modern apps
🧠 Key Takeaways
Keep answers short, clear, and structured in interviews
Use examples wherever possible
Focus on real-world usage instead of just definitions
✔️ Now the formatting is:
Even spacing
Clean bullets instead of broken tables
Consistent headings
Easy to read for blogs/interviews
🚀 L2 Round – C# Coding Questions
1️⃣ First Non-Repeating Character in a String
📌 Problem
Write a C# program to:
Take a string input
Find the first non-repeating character
Conditions:
Case-insensitive (
A == a)Ignore whitespace
✅ Solution
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
Console.WriteLine("Enter a string:");
string input = Console.ReadLine();
// Normalize: lowercase + remove spaces
string processed = input.Replace(" ", "").ToLower();
Dictionary<char, int> freq = new Dictionary<char, int>();
// Count frequency
foreach (char c in processed)
{
if (freq.ContainsKey(c))
freq[c]++;
else
freq[c] = 1;
}
// Find first non-repeating character
foreach (char c in processed)
{
if (freq[c] == 1)
{
Console.WriteLine("First non-repeating character: " + c);
return;
}
}
Console.WriteLine("No non-repeating character found");
}
}
🧠 Logic
Convert string → lowercase
Remove spaces
Count frequency using dictionary
Traverse again to find first char with count = 1
2️⃣ Find Missing Number in Array (1 to n)
📌 Problem
Array contains numbers from 1 to n
One number is missing
Find the missing number
✅ Solution (Using Sum Formula)
using System;
class Program
{
static void Main()
{
int[] arr = {1, 2, 4, 5}; // n = 5
int n = arr.Length + 1;
int expectedSum = n * (n + 1) / 2;
int actualSum = 0;
foreach (int num in arr)
{
actualSum += num;
}
int missingNumber = expectedSum - actualSum;
Console.WriteLine("Missing Number: " + missingNumber);
}
}
🧠 Logic
Sum of first n numbers =
n(n+1)/2Subtract actual array sum
Result = missing number
🧠 Key Takeaways
Use Dictionary for frequency-based problems
Focus on clean logic + edge cases in L2 rounds
Comments
Post a Comment