Posts

Showing posts from April, 2025

.NET Interview Questions with Answers

What is Polymorphism? Answer : Polymorphism is the ability of a method, function, or object to take on different forms. It allows objects of different types to be treated as objects of a common supertype, and the correct method is invoked depending on the object’s actual type. What is Method Overloading? Answer : Method overloading is when multiple methods in the same class have the same name but different parameters (either in type, number, or both). The appropriate method is chosen based on the method signature. What is the difference between ref and out? Answer : ref : The variable must be initialized before being passed to the method. out : The variable does not need to be initialized before being passed to the method but must be assigned a value inside the method. What is the static method? Answer : A static method belongs to the type itself rather than an instance of the class. It can be called without creating an instance of the class. Why...

OOPS concepts with real time example OMS

Order management typically involves processing customer orders, tracking items, calculating prices, handling shipments, and managing customer information.  Real-time Example: Order Management System Imagine you are building an Order Management System (OMS) or an e-commerce platform. This system allows customers to place orders, track items in their orders, calculate prices, and update order statuses. We'll design classes and methods that demonstrate the core OOP concepts in C#. ___________________________________________________ 1. Classes and Objects Concept: A class defines the structure and behavior of objects. We'll create classes like `Order`, `Customer`, `Product`, and `Payment`. Real-time example: csharp public class Product {     public string Name { get; set; }     public decimal Price { get; set; }     public Product(string name, decimal price)     {         Name = name;         Price = price;...

Third Highest Salary in SQL

SELECT salary FROM (     SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rank     FROM employees ) AS ranked_salaries WHERE rank = 3;

To find duplicate characters in a string in C#,

Program : using System; using System.Collections.Generic; class Program {     static void Main()     {         string input = "programming";         FindDuplicateCharacters(input);     }     static void FindDuplicateCharacters(string input)     {         Dictionary<char, int> charCount = new Dictionary<char, int>();         // Iterate through each character in the string         foreach (char c in input)         {             if (charCount.ContainsKey(c))                 charCount[c]++;             else                 charCount[c] = 1;         }         // Display duplicates         Console.WriteLine("Duplicate...

Second Highest Salary using C# Linq

using System; using System.Linq; public class Program {     public static void Main()     {         int[] numbers = { 5, 12, 3, 9, 21, 21, 7 };         var secondHighest = numbers                             .Distinct() // Remove duplicates                             .OrderByDescending(x => x) // Sort in descending order                             .Skip(1) // Skip the highest                             .FirstOrDefault(); // Take the second highest         Console.WriteLine($"Second highest number is: {secondHighest}");     } }