Thursday, October 22, 2026
HomeC#.NET Core Interview Questions - Programming In CSharp

.NET Core Interview Questions – Programming In CSharp


As a .NET developer, I’ve been in lots of interviews at corporations like Microsoft, Deloitte, and others from Forbes 500. An enormous a part of the interviews was about information buildings and algorithms. I additionally acquired many .NET Core and ASP.NET questions.

I’ll attempt to provide the questions that seem essentially the most within the interviews.

What’s SOLID?

The SOLID ideas are a set of pointers for object-oriented programming. These ideas are meant to make software program designs extra comprehensible, versatile, and maintainable.

SOLID stands for:

  • Single accountability. Which means a category ought to do just one factor. Overlook about lessons which have hundreds of strains.
  • Open-close. The open-close precept means a category must be open for extensions however closed for modifications.
  • Liskov substitution. Objects must be replaceable with cases of their subtypes with out altering the correctness of this system. So use the interfaces as a substitute of lessons.
  • Interface segregation. Some specialised interfaces are higher than a normal interface. No person ought to implement strategies of an interface that they don’t want.
  • Dependency Inversion Precept

What represents DRY?

DRY is a programming precept that stands for Don’t Repeat Your self. Which means you don’t write the identical code twice. Every time you have to write the identical code, you extract that part into a technique or perhaps a class.

How do you write a middleware?

You will need to have a technique known as Invoke or InvokeAsync. Additionally, your middleware can obtain the delegate for the following middleware within the pipeline.

public class ExampleMiddleware
{
    non-public readonly RequestDelegate _nextMiddleware;

    public RequestCultureMiddleware(RequestDelegate nextMiddleware)
    {
        _nextMiddleware = nextMiddleware;
    }

    public async Activity InvokeAsync(HttpContext context)
    {
        //right here you'll be able to entry the request physique/headers/cookies/url and so forth.
        await _nextMiddleware(context); // name the following middleware
    }
}

What’s the distinction between calling a middleware with the strategies app.Use and app.Run?

The Usemethodology receives a delegate parameter that represents the following middleware within the pipeline. A Run delegate is a terminal middleware as a result of it doesn’t obtain a reference to the following middleware.

app.Use(async (context, subsequent) =>
{
    await subsequent.Invoke(); //calling the following middleware within the pipeline
});

app.Run(async context =>
{
    await context.Response.WriteAsync("Right here the pipeline ends. Now it goes again!");
});

What’s the distinction between middleware and filters in ASP.NET Core?

A middleware will carry out duties earlier than and after a request is processed whereas the filter is executed on the request processing pipeline.

Middlewares can run on all requests, whereas filters solely execute on specific controllers or actions.

Middlewares operates solely on HttpContext, whereas filters have entry to MVC or Razor web page objects like ModelState.

What are some great benefits of .NET Core over .NET Framework?

  • .NET Core is cross-platform. It runs on Home windows, Linux, and macOS. It may be used very simply for cloud environments.
  • It’s constructed from scratch and far sooner than the older .NET Framework. Dotnet Core is extra light-weight and modular than the .NET framework.
  • It’s free and open-source. Anybody could make enhancements to the repository.

What’s NuGet?

Nuget is a package deal supervisor for .NET tasks. It may be used so as to add third-party libraries and frameworks to your undertaking. You should use NuGet to maintain your libraries up-to-date. For frontend libraries, you must use package deal managers like npm or yarn.

When to decide on Parallel.For as a substitute of async and await?

The Parallel class is designed for parallelism. It must be used for heavy CPU processing duties that may be executed in parallel. For instance, normally, picture processing duties will be applied in parallel.

Then again, async and await key phrases are designed for duties that should await earlier duties to be accomplished. For instance, you wish to write the supply code of an internet site in a textual content file. Each operations are blocking the present thread till it finishes.

You’ll be able to learn extra concerning the Parallel class in this text.

In ASP.NET Core, what are the names of the companies primarily based on their lifetime?

In ASP.NET Core, we’ve got three kinds of companies:

  1. Singleton
  2. Scoped
  3. Transient

What’s the distinction between a scoped and a transient service?

A scoped service is identical inside a request. For instance, the identical occasion is supplied if a service is injected inside one other service and a controller.

A transient service means a brand new occasion is supplied each time the service is injected.

Why will we use dependency injection?

Dependency injection lets you separate the creation of an object from its use. This enables us to inject completely different cases into completely different conditions. For instance, you have got a category with a database connection object injected. If you wish to write unit exams for that class, you most likely don’t need truly to name the database. So, you’ll be able to inject a special occasion that mocks your database.

Utilizing dependency injection, you keep away from writing the identical code that instantiates an object. Your lessons will look cleaner.

What’s the distinction between Required and BindRequired attributes?

Required solely works for reference varieties. Within the case of worth, variable varieties Required don’t work as a result of the variables get the default worth.

For instance, within the case of Integer variables, the default worth is zero(0).

That is why you must use the BindRequired attribute for worth variable kind to make sure that a parameter is certain.

You’ll be able to learn extra about Required and BindRequired attributes in my article.

Which route does have precedence: the attribute route or the standard route?

The attribute route has precedence.

What’s the distinction between GET and POST strategies?

  • A GET methodology is much less safe as a result of parameters are despatched on to the URL
  • A GET motion will be cached and bookmarked. POST actions can’t be cached or bookmarked.
  • A GET can solely ship ASCII characters. Within the case of a POST, you don’t have limitations; you’ll be able to ship binary, strings, and particular characters.
  • Internet Browser normally accepts URLs with a most of 255 characters. A physique of a POST methodology is restricted solely by the servers. So, you’ll be able to ship fewer information on GET actions as a substitute of POST.
  • GET strategies are used to request information. Then again, POST strategies are used to save lots of or ship info and carry out actions requiring the parameters to be hidden, like a login web page.

What’s Kestrel, and why do we’d like it?

Kestrel is an open-source internet server. As a substitute of IIS, Kestrel is cross-platform, so ASP.NET Core will work on any working system that .NET Core helps.

Kestrel can be utilized at the side of IIS, however as a result of IIS shouldn’t be cross-platform, it should solely work for Home windows. That’s why we’d like Kestrel for ASP.NET Core to be cross-platform.

In case we use a reverse proxy like IIS or Nginx, then the Kestrel server must be positioned after within the request pipeline.

What’s the distinction between Razor Pages and MVC?

Razor Pages use the MVVM(Mannequin-View-ViewModel) sample, and MVC makes use of Mannequin View Controller. Razor pages use page-based routing, whereas MVC makes use of controllers to handle requests.

Why is really helpful to cross the information to a ViewModel once we are rendering a view?

We cross a view mannequin as a substitute of a mannequin as a result of normally, we don’t wish to expose your entire object, or possibly the view wants properties of a few objects. So as a substitute of passing pointless information, we give an object that accommodates solely the required information.

How do you retain the configuration for every setting within the software settings file?

App settings file can have the setting within the file title: appsettings.Improvement.json.

What’s the distinction between the JSON methodology and the Content material methodology?

Json returns the right MIME kind for JSON, whereas Content material doesn’t.

What kind of HTTP verbs are you aware?

The HTTP verbs are GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS.

When do you utilize PUT and when do PATCH?

We do use PUT when the consumer sends your entire object. The PATCH methodology is used when the consumer sends solely partial information.

What’s OWIN?

OWIN stands for Open Internet Interface for .NET. It describes how internet purposes and servers must be decoupled to maneuver to different environments shortly.

What’s the distinction between Dispose and Finalize strategies?

Finalize methodology is known as by Rubbish Collector every time it thinks it’s obligatory. So that you don’t know when it will occur. The Dispose methodology must be known as out of your code as a substitute. Dispose is used to shut and clear unmanaged sources like database connections, file handlers, and HTTP connections.

Title three benefits of Microservice structure

  1. The microservice will be written in any programming language.
  2. Totally different groups can work on different elements of the undertaking. Every group can select its desired programming language for improvement.
  3. Microservice structure will be simply scaled. Within the case of a monolith software, you should scale the entire software. In a microservice structure, you’ll be able to scale just some companies. There are instruments like Kubernetes that orchestrate the containers of the companies.
  4. You’ll be able to replace the service simply in comparison with a monolith software.
  5. Errors are remoted. If a microservice has an error, the error is separated from the opposite companies. For instance, let’s assume you have got a web-based retailer and the checkout service has an error. The login service will nonetheless work as a result of it doesn’t intrude with that service.

Why will we use Docker containers?

Docker containers are a safe method to construct and ship remoted items. Containers allow programmers to work with the identical libraries and configurations throughout a number of environments. As a programmer, utilizing a Docker container, you don’t fear concerning the working system or machine configuration.

Additionally, utilizing an orchestrator, you’ll be able to handle the useful resource between containers.

How do you shield towards a CSRF assault?

To guard towards a CSRF assault, we generate an anti-forgery token, and we validate this token on the server facet utilizing [ValidateAntiForgeryToken].

What does state administration in ASP.NET Core imply?

The HTTP protocol doesn’t retailer the person’s information between requests. Which means the ASP.NET Core framework ought to present a method to retailer the information between requests.

In ASP.NET Core, what are the accessible choices for retaining the state between requests?

In ASP.NET Core, you need to use for retaining the state one of many following storages:

  1. Cookies
  2. TempData
  3. Cache
  4. Session state
  5. Hidden Fields
  6. Question strings
  7. HttpContext gadgets

How will we deal with file add in ASP.NET Core?

In ASP.NET Core, we deal with file add utilizing the IFormFile interface:

public IActionResult ProfilePhoto(IFormFile file)
{
    if (file == null || file.Size == 0)
    {
        return BadRequest("File not uploaded");
    }

    var path = Path.Mix(
        Listing.GetCurrentDirectory(), "wwwroot",
        file.FileName);

    utilizing (var stream = new FileStream(path, FileMode.Create))
    {
        file.CopyTo(stream);
    }

    return RedirectToAction("Index");
}

How do periods works in ASP.NET?

When a person visits for the primary time the web site, a session id is generated and saved within the person’s cookies. When the person returns to the web site, ASP.NET retrieves this cookie and will get the session’s saved values.

What’s a Well being Examine, and the way do you configure one in ASP.NET Core?

A well being examine answer supplies a manner for the applying customers to examine that the service works.

A easy well being examine will be applied by including the next service:

_services.AddHealthChecks();

You additionally implement the well being examine middleware within the pipeline:

app.MapHealthChecks("/well being");

If the service is unavailable, you’ll get an HTTP response standing code 503 Service unavailable.

How do you configure Logging in ASP.NET Core purposes?

In ASP.NET Core purposes, you need to use Microsoft.Extensions.Logging package deal. Utilizing the ILogger interface, you’ll be able to log messages.

utilizing Microsoft.Extensions.Logging;

class MyClass
{
    non-public readonly ILogger<MyClass> _logger;

    public MyClass(ILogger<MyClass> logger)
    {
        _logger = logger;
    }

    public void DoWork()
    {
        strive
        {
            // Do some stuff
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "An error occurred whereas executing code.");
        }
    }
}

For the logging configuration, you must use the ILoggerFactory interface:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
    // Configure logging
    loggerFactory.AddConsole();
    loggerFactory.AddDebug();
    // Add different logging suppliers as wanted
    // ---
}

Additionally, you need to use well-liked libraries like NLog or Serilog.

Title 3 ways of operating background duties in ASP.NET Core

  1. Utilizing a library like HangFire
  2. Utilizing hosted companies. For this, you must implement the IHostedService. This methodology defines two strategies:
  3. Utilizing Activity.Run methodology
  4. Utilizing BackgroundWorker class

What are the completely different kind’s outcomes you could return from an motion in ASP.NET Core?

Within the ASP.NET controller’s motion, you’ll be able to return:

  • ViewResult – returns a view, which is a Razor template that’s used to render HTML
  • ContentResult – returns a string of content material, usually used for returning plain textual content or HTML
  • JsonResult – returns a JSON-formatted object, which can be utilized to return information to a client-side script
  • FileResult – returns a file, reminiscent of a PDF, textual content file, or picture
  • RedirectResult – redirects the consumer to a special URL
  • RedirectToActionResult – redirects the consumer to a special motion methodology inside the identical controller
  • RedirectToRouteResult – redirects the consumer to a special route
  • StatusCodeResult – returns a selected HTTP standing code, reminiscent of 404 (Not Discovered) or 500 (Inside Server Error)
  • ObjectResult – returns an object
  • EmptyResult – returns an empty end result

What’s OWASP?

OWASP stands for Open Internet Utility Safety Challenge. OWASP TOP 10 lists essentially the most frequent threats to internet purposes.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments