Posts

Generate 100 records using linq c#

using System; using System.Collections.Generic; using System.Linq; class Program {     static void Main()     {         // Generate a 100 records using linq c#         List<Employee> employees = Enumerable.Range(1, 100).Select(i => new Employee         {             Id = i,             Name = "Employee " + i,             Age = new Random().Next(22, 60),             Department = i % 2 == 0 ? "IT" : "HR",             Salary = new Random().Next(30000, 100000)         }).ToList();         // Query 1: Get employees from IT department with salary > 50,000         var highSalaryITEmployees = employees             .Where(e => e.Department == "IT" && e.Salary...

how to find salary in linq

https://youtube.com/shorts/cfdwiuK8SO4?si=9CobFUcaZ3YYC89-

Finding 2nd and 3rd Highest and Lowest Salaries Using LINQ

Finding 2nd and 3rd Highest and Lowest Salaries Using LINQ 1. 2nd Highest Salary: var secondHighestSalary = employees     .OrderByDescending(e => e.Salary)     .Select(e => e.Salary)     .Distinct()     .Skip(1)     .FirstOrDefault(); 2. 3rd Highest Salary: var thirdHighestSalary = employees     .OrderByDescending(e => e.Salary)     .Select(e => e.Salary)     .Distinct()     .Skip(2)     .FirstOrDefault(); 3. 2nd Lowest Salary: var secondLowestSalary = employees     .OrderBy(e => e.Salary)     .Select(e => e.Salary)     .Distinct()     .Skip(1)     .FirstOrDefault(); 4. 3rd Lowest Salary: var thirdLowestSalary = employees     .OrderBy(e => e.Salary)     .Select(e => e.Salary)     .Distinct()     .Skip(2)     .FirstOrDefault();

Finding 2nd and 3rd Highest and Lowest Salaries Using SQL

Finding 2nd and 3rd Highest and Lowest Salaries Using SQL 1. 2nd Highest Salary: SELECT MAX(Salary)  FROM Employee  WHERE Salary < (SELECT MAX(Salary) FROM Employee); 2. 3rd Highest Salary: SELECT MAX(Salary)  FROM Employee  WHERE Salary < (SELECT MAX(Salary)  FROM Employee WHERE Salary < (SELECT MAX(Salary) FROM Employee)); 3. 2nd Lowest Salary: SELECT MIN(Salary)  FROM Employee  WHERE Salary > (SELECT MIN(Salary) FROM Employee); 4. 3rd Lowest Salary: SELECT MIN(Salary)  FROM Employee  WHERE Salary > (SELECT MIN(Salary)  FROM Employee WHERE Salary > (SELECT MIN(Salary) FROM Employee)); @sqlserver @sql #dotnettechpro

Sonar qube for code scan

🚀 Ensure Code Quality with SonarQube! 🚀 As developers, maintaining high-quality code is crucial to delivering robust and maintainable software. 💻✨ One powerful tool I use to ensure code quality and eliminate code smells is SonarQube. SonarQube is an open-source platform that performs static code analysis to detect: 🔸 Code Smells 🔸 Bugs 🔸 Security Vulnerabilities 🔸 Technical Debt Here's how you can integrate SonarQube into your .NET projects: 1. Install SonarQube locally or use it on the cloud. 2. Analyze your codebase by integrating SonarQube with your CI/CD pipeline (Azure DevOps, GitHub Actions, Jenkins, etc.). 3. Get insights into code smells, security issues, and improvements with detailed reports. Using SonarQube has helped me catch early bugs and write cleaner code, which ultimately results in more efficient and maintainable applications. 🛠️ Takeaway: Embrace tools like SonarQube for better code quality and seamless delivery! #DotNetTechPro #SonarQube #CodeQuality #Cl...

All remaining Dotnet Developer Interview questions and answers which I was facing

Here are the answers for the remaining questions: 14. Multiple Return Types from a Method Answer: You can return multiple values from a method using Tuple, out parameters, or a custom object. Example using Tuple: public (int, string) GetMultipleValues() {     return (1, "Result"); } var result = GetMultipleValues(); Console.WriteLine($"ID: {result.Item1}, Value: {result.Item2}"); --- 15. Private Constructor Answer: A private constructor is used to prevent the instantiation of a class from outside the class. It’s typically used in singleton patterns. Example: public class MyClass {     private MyClass() { }  // Private constructor } --- 16. Method Hiding Answer: Method hiding occurs when a method in a derived class has the same name and signature as one in its base class but is marked with the new keyword. This hides the base class implementation. Example: public class BaseClass {     public void Display() { Console.WriteLine("Base Display"); } } public...

Dotnet Interview questions and answers real time Which I am facing

Here are detailed answers to some of the questions you asked: 1. Async Method Execution Time Question: If MethodA starts at 11:00, when will it return true? Answer: The time when MethodA returns depends on the execution times of MethodB and MethodC. Since both methods are awaited, MethodA will return true only after both MethodB and MethodC complete. If MethodB and MethodC take 5 seconds each, then MethodA will return true after 10 seconds (i.e., at 11:00:10). --- 2. LINQ Query to Get Top 3 Salaries Department-wise SQL Query: SELECT Department.name, emp.id, emp.name, emp.salary FROM Employee emp JOIN Department ON emp.depid = Department.depid WHERE emp.salary IN (SELECT TOP 3 salary FROM Employee e WHERE e.depid = emp.depid ORDER BY salary DESC) ORDER BY Department.name, emp.salary DESC; LINQ Query: var result = context.Employees              .GroupBy(e => e.DepartmentId)              .SelectMany(g => g.OrderByD...