Download Logo

Access modifiers

Class Accessibility Matrix Diagram What is Default accessibility of class Internal Difference between Internal and Protected Internal Look above image for clarification 1. Public Accessibility: The class is accessible from any other class or assembly. Usage: When you want the class to be widely accessible. 1 2 3 4 5 // Public class can be accessed from anywhere public class PublicClass { public string Name { get; set; } } 2. Internal Accessibility: The class is accessible only within the same assembly (project). Usage: When you want to limit access to within the assembly, which is useful for encapsulation. 1 2 3 4 5 // Internal class can only be accessed within the same assembly internal class InternalClass { public string Name { get; set; } } 3. Protected Accessibility: The class itself cannot be protected, but its members can be. A class can be derived from a base class with protected members. Usage: When you want to allow access to members only in derived classes. 1 2 3 4 5 6 7 8 9 10 11 12 13 public class BaseClass { protected string Name { get; set; } } public class DerivedClass : BaseClass { public void PrintName() { // Accessing protected member from the base class Console.WriteLine(Name); } } 4. Private Accessibility: A class itself cannot be private, but its members can be. Private members are only accessible within the same class. Usage: When you want to restrict access to the class members to only within the class itself. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 public class MyClass { private string Name { get; set; } public void SetName(string name) { Name = name; } public string GetName() { return Name; } } 5. Protected Internal Accessibility: The class or member is accessible within the same assembly and also to derived classes in other assemblies. Usage: Useful for situations where you want to expose class members to derived classes or within the assembly. 1 2 3 4 public class MyClass { protected internal string Name { get; set; } } 6. Private Protected Accessibility: The class or member is accessible within the same class or in derived classes that are in the same assembly. Usage: A more restrictive version of protected internal, useful for fine-grained access control. 1 2 3 4 public class MyClass { private protected string Name { get; set; } }

August 3, 2024 · 2 min · 405 words · PrashantUnity
Download Logo

ActionResult types

What is the difference between ‘ViewResult’ and ‘ActionResult’? In ASP.NET MVC, both ViewResult and ActionResult are classes that represent the result of an action method. The primary difference between them lies in their level of abstraction. ActionResult: ActionResult is the base class for all action results in ASP.NET MVC. It provides a high level of abstraction, allowing action methods to return various types of results, such as ViewResult, RedirectResult, JsonResult, etc. ...

August 3, 2024 · 2 min · 251 words · PrashantUnity
Download Logo

ADO.NET Q&A

1. What is ADO.NET? ADO.NET (ActiveX Data Objects) is a data access technology in the .NET framework used to interact with data sources, such as databases. It provides a set of classes for connecting to databases, executing commands (queries, updates), and retrieving results into datasets or data readers. 2. Differentiate between DataSet and DataReader DataSet: It’s an in-memory cache of data retrieved from the database. It can hold multiple DataTables, relationships, and constraints. It is disconnected, meaning it doesn’t need an active connection to the database once data is loaded. DataReader: It provides a read-only, forward-only stream of data from the database. It’s faster and uses less memory compared to DataSet but is less flexible as it doesn’t store data locally. 3. Explain the steps to connect to a database using ADO.NET To connect to a database using ADO.NET: ...

August 3, 2024 · 3 min · 437 words · PrashantUnity
Download Logo

App settings in .NET

Reading Configuration from appsettings.json 1 2 3 4 5 var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); var val =config["randomString"]; Binding Configuration to Static Classes 1 2 3 4 5 6 7 8 9 10 11 12 13 public static class RandomClass { public const string hello = "hello"; public static readonly string bello = "90"; static RandomClass() { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); bello = configuration["MySettings:Bello"]; } } 1. Add appsettings.json to Your Project Ensure you have an appsettings.json file in the root of your project. It might look something like this: ...

August 3, 2024 · 3 min · 434 words · PrashantUnity
Download Logo

ASP.NET Core middleware

How does middleware differ from HTTP modules in ASP.NET? Middleware in ASP.NET Core is a more flexible and lightweight approach compared to HTTP modules in traditional ASP.NET. Middleware can be added or removed easily in the application’s startup configuration. It allows for better control over the request pipeline and can be organized into a pipeline of components, whereas HTTP modules are more tightly coupled and don’t offer the same level of flexibility. ...

August 3, 2024 · 2 min · 414 words · PrashantUnity
Download Logo

Last-minute interview prep

Programming Questions 1. Array Manipulation: Move all zeros to the end of a given array. Solve the problem of buying and selling a product to maximize profit, given its prices on different days from a given price array. Find the 3rd highest element in an array. Find the 2nd duplicate number in an array. 2. String Manipulation: Given a string s, find the length of the longest substring without repeating characters. (Example: s = "abcabcbb") Find the first repeating number in an array. (Example: arr[] = {10, 5, 3, 4, 5, 3, 6}) Given a List<string>: var list = new List<string> {"Ravi Kumar", "Neha Gupta", "Arti Gupta", "Kamal Rai"}; get the count of the surnames and maintain the order. 3. C# Code Execution: Determine the order of printing in a C# class with static constructors, instance constructors, and regular constructors. General Problem-Solving: Dry run a piece of code and optimize its complexity. C# Core Concepts 1. LINQ (Language Integrated Query): Steps for initializing LINQ queries. How intermediate operations work in LINQ (e.g., Where, Select). How terminal operations work in LINQ (e.g., ToList(), FirstOrDefault()). What is a parallel LINQ (PLINQ) query? 2. Collections Framework: Difference between IComparable and IComparer. How Dictionary<TKey, TValue> works in C#. Difference between ICollection and IEnumerable. Overview of the Collection framework starting from the base interface IEnumerable and its methods. 3. Exception Handling: How to create custom exceptions in C#. Difference between Thread.Sleep() and Task.Delay() methods. 4. Polymorphism and OOP Concepts: Method overloading and method overriding. Difference between == and .Equals() in string comparison. Multithreading and the use of lock statements. Understanding marker interfaces, functional interfaces (like delegates), and design patterns such as Singleton and Factory. SOLID principles. 5. ASP.NET Core: Difference between ASP.NET Core MVC and Web API, and which is better and why. ASP.NET Core inbuilt server (Kestrel). Difference between Razor Pages and MVC. Understanding JWT tokens and how they secure applications using HTTPS. 6. Miscellaneous C#: Understanding the order of execution in blocks (static constructor, instance constructor, regular constructor). Questions related to classes and methods, such as Animal and Cat with overridden methods. SQL: 1. Complex Queries: Find the third-highest salary in SQL. Understanding the order of execution in SQL queries (e.g., Empid, dept, manager id). 2. Data Structures and Algorithms (DSA): Array and String Problems: ...

August 3, 2024 · 12 min · 2456 words · PrashantUnity
Download Logo

MVC filters

What do you understand by filters in MVC? Filters are components that enable developers to inject logic into the request processing pipeline at various stages. Filters are used to perform tasks such as logging, authentication, authorization, exception handling, caching, and more. Filters provide a way to encapsulate cross-cutting concerns. Filters can be applied globally to the entire application or selectively to specific controllers or action methods. There are several types of filters in ASP.NET MVC: ...

August 3, 2024 · 3 min · 585 words · PrashantUnity
Download Logo

MVC request lifecycle

Explain the MVC application life cycle Any web application has two primary execution steps: Understanding the request Sending out an appropriate response MVC application life cycle includes two main phases: Creating the request object Sending response to the browser The steps included in creating a request object are: Request Routing: When a user makes a request, the ASP.NET MVC application starts by using a routing engine to determine which controller and action method should handle the request. The route configuration defines how URLs map to controllers and actions. Controller Execution: ...

August 3, 2024 · 3 min · 432 words · PrashantUnity
Download Logo

MVC routing Q&A

How is routing carried out in the MVC pattern? The routing mechanism in ASP.NET MVC is responsible for determining which controller and action should handle a particular request based on the URL of the request. The routing process typically involves the following steps: Incoming Request: When a user makes a request to our ASP.NET MVC application by entering a URL in the browser, the request is received by the ASP.NET runtime. ...

August 3, 2024 · 4 min · 802 words · PrashantUnity
Download Logo

MVC set — starter

What is ASP.NET MVC Core? ASP.NET MVC Core is a modern, open-source, cross-platform framework for building web applications. It is a part of the larger ASP.NET Core framework and follows the Model-View-Controller (MVC) architecture pattern. MVC Core is designed to offer greater performance, scalability, and flexibility compared to its predecessors. It allows developers to create web applications that can run on various platforms (Windows, Linux, macOS) and supports cloud-based deployment. Key features include: ...

August 3, 2024 · 40 min · 8437 words · PrashantUnity