0% found this document useful (0 votes)
8 views16 pages

Interview2 Q&a

The document is a transcript of a mock interview conducted by N with Iran, a .NET developer. The interview covers various topics related to .NET, C#, OOP concepts, ASP.NET MVC, and other technical aspects relevant to the field. Iran answers questions about programming concepts, memory management, and frameworks, demonstrating his knowledge and experience in the industry.

Uploaded by

Aman Gawande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views16 pages

Interview2 Q&a

The document is a transcript of a mock interview conducted by N with Iran, a .NET developer. The interview covers various topics related to .NET, C#, OOP concepts, ASP.NET MVC, and other technical aspects relevant to the field. Iran answers questions about programming concepts, memory management, and frameworks, demonstrating his knowledge and experience in the industry.

Uploaded by

Aman Gawande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Statement:

Hello guys, how are you? I am N, and today I am with Iran. He is a .NET
developer working in the industry for the last four to five years. He's working on
different technologies like .NET and SQL and other kinds of things, you know.
So I decided to start a series of mock interviews so that you people, if you want
to clear .NET interviews, ReactJS, and SQL interviews, you have a little idea of
what kind of actual questions people ask in the industry.
So it is our first interview, the mock interview, and today I will conduct the
interview of Iran. Basically, it will be related to .NET and OOP concepts, and then
we will move forward.
Statement:
Iran Bhai, thank you so much for giving the time. I would like to introduce
yourself, and then we will start the interview.
Answer:
Yeah, my pleasure N. So, first of all, I want to introduce myself—a short intro.
So currently, I am working as a senior full-stack developer in .NET owned by
Aram.
So, my responsibilities include integrations in existing products and
improvements or the development of new modules.
So, this is the short intro.
Statement:
Okay, thank you so much for giving the introduction. Now, if you are ready, then
we can move forward for the interview. Are you ready, sir?
Answer:
Yeah, yeah, I'm okay.
Question:
Sir, I think in your CV you mentioned that you are working on .NET 8 and other
latest technologies. So can I just ask which latest version we are using at the
moment of C# in 2024?
Answer:
Yeah, the latest version, I think, is probably 12, which was released in 2023.
Statement:
Yes, correct! .NET 8.0. Okay, yes, correct! We are using the C# 12 version at the
moment, and the .NET version will be released this year, I think, or in the next
year. So at the moment, we are using the C# 12 version with .NET 8.
Statement:
Now, we are using different types of variables in normal .NET programming,
different types of classes and strings.
But actually, if I just ask, it is a simple question—what is the difference between
value type and reference type in C#?
Answer:
The primitive data types like integer, long, float, and double are value types. And
the classes, interfaces, delegates, and strings—these are reference types.
And value types are stored on the stack, and reference types are stored in the
heap. Basically, it is sort of the memory management.
Statement:
Okay, nice! You said that we are using value type on the stack and reference
type on the heap memory, correct?
Answer:
No.
Statement:
We are using different types of classes like sealed class, static class, abstract
class, and obviously, we are also using interfaces in C#.
Now, my question is, what is the difference between abstract class and an
interface in OOP?
Answer:
Yeah, interface is a contract. So if I have inherited an interface, I have to
implement all its methods.
And the abstract class is a class by itself. We cannot instantiate the abstract
class.
Statement:
Okay, you said that we can't instantiate—you mean we can't create an object of
the abstract class?
Answer:
Yeah.
Statement:
So, can we write method body inside the interface?
Answer:
Yes, of course—inside the interface, we... Sorry, no, no, no.
Okay, in the interface, we cannot write the body or definition of the routine or
method.
And in the abstract class, we have...
Statement:
Okay, okay, correct!
Now, there are some scenarios where we want to prevent the derived class from
inheriting from some parent class.
Now, to do this, how do you prevent a class from being inherited by its child
classes?
Answer:
Yeah, okay, N. If I want to restrict a class from inheritance, I have to declare it as
a sealed class.
Statement:
Okay, correct! We can use the sealed keyword with the class, and it will not be
inherited, right?
Answer:
Correct.
Statement:
I'm moving towards a very common question. It is about overloading and
overriding. How will you differentiate these two in object-oriented programming?
Answer:
Yeah, it is also a good feature of object-oriented programming. So, if I have a
method—in overloading, if I have a method, the signature of the method remains
the same, and the parameters passed have different data types or a different
count of parameters.
Okay, so yeah, we can achieve this way of overloading.
Overriding is a concept where if I have declared a class method in a base class,
and I have inherited the base class in a child class, when I have implemented the
method in the child class with overriding, it is a redefinition. So, this is the
concept of overriding.
Statement:
Okay, correct, you are right.
Now, obviously, you will also be using access modifiers in your programming.
Can you just tell me why we use access modifiers? Can you just tell me about
public and private?
Answer:
Yes, yeah, of course. To restrict the access to the resources of the classes or
methods.
Like, if I have declared properties or methods as public, this can be used by any
of the classes.
So, if I have declared private, private has its own scope and can be utilized within
the scope.
And protected—the class or member is accessible within its own class and any
derived class.
Statement:
Okay, now there is also internal. Would you please?
Answer:
Yeah, of course. The internal—the class or member is accessible within the same
assembly or project.
Statement:
Okay, correct. Nice!
Now, obviously, when the C# code is running, there are different things. My
question is, which part manages the memory in the CLR automatically? Did you
get it, or should I repeat the question?
Answer:
Garbage collector, I think.
Statement:
Yes, yes, you are right! The garbage collector is responsible for managing the
memory in the CLR, I mean, the Common Language Runtime. Correct!
Now, as we are on the CLR side, would you please explain the JIT compiler or, we
can say, just-in-time compiler?
Answer:
Now, you know, when I hit the F5 button to execute my code, before that, the JIT
compiler translates the IL code into native machine code.
Statement:
Okay, yeah, so you said that it is responsible for translating the Intermediate
Language code to the native code, which is basically bytecode for the machine?
Answer:
Yeah, yeah.
Statement:
Okay, right! Now, what is the difference—sorry, I am asking some questions
about the CLR.
What is the difference between managed and unmanaged code?
Answer:
Managed code is written in .NET CLR, okay?
So, unmanaged code is managed by the OS directly. This is the, like, simple
explanation.
Statement:
Okay, now, is it possible that managed code can access unmanaged code?
Answer:
Yes.
Statement:
So, if in your mind at the moment there is any explanation or example, would
you please share it with me?
Answer:
I think... right now, I can't explain.
Statement:
Okay, no issue.
Basically, we can access the unmanaged code from the managed code, and
there is, I think, some kind of P/Invoke. We are using the attribute DllImport and
then giving the DLL name. It is just above the class, and then we can access the
methods of the unmanaged code DLL.
So, we are using basically the DllImport attribute, and inside the parameter, we
are passing the DLL name. There are also some COM interop methods to access
the unmanaged code from managed code.
So, there are ways in .NET for accessing the unmanaged code.
Statement:
Okay, now, Iran, we mostly... You know, for example, I am getting a list from the
database. Then I am obviously saving it in some kind of object or some kind of...
Statement:
Models, uh, in my program. Now, what is the difference between an array and a
list?
Answer:
Yeah, I think an array is used for fixed-size data. Like, suppose I have 10 integers
or 10 students' data, so I can store them in an array.
Okay, so if I know, let's suppose, for a list, I have data of students—like, let's
suppose in a database—so we use, like, I use a list. I don't know—maybe today I
have 10 students, then another day maybe 100, and so on. So it is sort of the
management of their size.
Statement:
Okay, okay. Now, for example, there is a scenario to retrieve type information of
any object at runtime in C#. So how will you do this?
Answer:
You're... I think you're asking about reflection.
Statement:
Sorry, what did you say?
Answer:
Reflection.
Statement:
Yes, yes, yes. I am asking about this.
Answer:
Yeah, reflection is used to achieve this type of information at runtime.
Statement:
Okay, so at runtime, you said that we are using reflection to get type-related
information of any object or any class. Sure.
Okay, okay. So, Ifan, now I will just move towards ASP.NET MVC. We can ask lots
of questions from OOP, but we will keep the things not too lengthy. I will move
towards ASP.NET MVC. Have you worked on ASP.NET MVC?
Answer:
Yeah, yes, I have. And also, my domain is as a developer, so okay. This is without
ASP.NET MVC; I think it's not possible to have...
Statement:
Okay, so would you please tell me some component names or some folder
names inside the ASP.NET MVC project? I am not talking about .NET Core, but the
traditional ASP.NET MVC with .NET 4.7. What are the folders—can you just give
me any names or file names?
Answer:
Yeah, yeah—models, controllers, content, and scripts. ASP.NET, like web.config
type of structures of the project, and also areas and so on.
Statement:
Okay, so now you said that there are controllers folder, model folder, and, um,
content folder, yes?
Now, in ASP.NET MVC, you know that we are saving mostly the static files in the
content folder. But in .NET Core, there is a specific folder for saving static files.
So where do we keep static files like images, CSS files, in the .NET Core project?
Answer:
In the .NET Core project, we keep these types of data or files in the wwwroot
folder.
Statement:
Okay, so for example, if I keep the files outside of the wwwroot folder—for
example, I add a new folder to the project and then keep some images there—
will it be accessible within the Razor view?
Answer:
I think not. To be honest, I am not sure about this, but I think it will not be
accessible. That is why they recommend using the wwwroot folder.
Statement:
Okay, I will also check on my side.
Okay, obviously, if you are working on ASP.NET MVC, then we are using partial
views. So, how do you use a partial view in ASP.NET MVC 5? I mean in version 4.7
and in .NET Core Razor View. Is there a specific difference in how to call the
partial view?
Answer:
I think the difference is that we use partial views to add the repetitive parts of
the code to achieve the functionality.
So, in ASP.NET MVC 5, we use @Html.Partial() to call the partial view and pass
the data.
In .NET Core, we use @await Html.PartialAsync() or just @Html.Partial().
Statement:
Yes, correct. We are using it this way. There are also some other ways, but it is
the most common way.
If, in an MVC application, you know that we get the request and then, according
to the request, an action method is invoked. Then we mostly call the database,
bind the data with some models or other things, and then return to the view.
Now, give me the names of four ways—just four ways—to return the data from
the controller to the view.
Answer:
Model, ViewBag, ViewData, and TempData.
Statement:
I think you are correct. Yes, we can also pass by model, and it is the most
common way. We can also use TempData and, obviously, ViewData and ViewBag.
We can also, I think, for some scenarios, use the session to store data for global
access throughout the application.
But you are correct, we can use the ways that you mentioned.
Now, Ifan, I will just ask you about... Have you ever heard about action filters in
ASP.NET MVC?
Answer:
Yes.
Statement:
So would you please define them?
Answer:
Yes, sure. Action filters in ASP.NET MVC are a type of filter that we can apply to
controllers or action methods.
They allow us to execute code before or after specific steps in the processing
pipeline.
Statement:
Okay, now you said that if you want to perform some kind of action before and
after, then action-executing and action-executed are the two methods?
Answer:
Yes, yes, yes, you are correct. We use the filters on OnActionExecuting or
OnActionExecuted if we want to execute some kind of activity before or after the
controller hit or the action method.
Statement:
Okay, now, for example, I say to you that you have to save the username in a
session in ASP.NET MVC and in ASP.NET Core MVC. You just have to save the
username in a session, but there is some syntax difference between .NET
Framework and .NET Core.
Statement:
Give me a little, uh, I mean, hint.
Answer:
Yeah, yeah, HttpContext.Session.SetString() with given two parameters, as we
pass in functions. Like in ASP.NET, HttpContext.Current.Session["key"] = value;
Statement:
Okay, yes, you are correct. In .NET Framework, we use the HttpContext class,
then Current.Session, and then use an array with a string to pass the session
name and value.
In .NET Core, as you said, we use SetString() with the key name and the value.
Now, in .NET Core, which type of object do we use for handling the file in the
controller? For example, you have to save an image, you fill the form, and then
send the image to the controller. In the controller, which type of interface or
variable will we use to get the file?
Answer:
In .NET Core, we mostly use IFormFile.
Statement:
Okay, correct. Now, in .NET Core applications, you know the concept of
middleware is very important. We can use middleware according to our
requirements, and we can create new middlewares.
If you just give me a little definition—what is basically the middleware in a .NET
Core application?
Answer:
Yeah, it is a very important concept and also an interesting one. Basically, we use
middleware to handle the request processing pipeline.
Middleware components are used to handle requests and responses in the
pipeline.
Statement:
Okay, okay. Now, if I give you a simple task to create a middleware...
The purpose of this middleware is that if the URL contains the keyword "Iran",
then the middleware should just print or return something.
I just want to declare a middleware that detects "Iran" in the URL.
Would you just give me an idea or understanding?
Answer:
Yeah, sure. You are asking how to create and use custom middleware.
We will declare a class named IdentifyIranUrlMiddleware, and we will inherit from
the IMiddleware interface.
Statement:
Okay, you said you will declare a class named IdentifyIranUrlMiddleware and
inherit from the IMiddleware interface?
Answer:
Yeah, yeah, or you can give any other name. The main point is that we will
inherit from the IMiddleware interface.
Statement:
Okay, and if I just say we are using a method—can you give me the method
name?
A public async task—any method name that comes to your mind, which method
are we using?
Answer:
Inside the middleware class, we mostly use a method to forward the request, like
await next().
Statement:
What is the method name? If I give you the first keyword of the name: Invoke...
Answer:
InvokeAsync()
Statement:
Okay, okay. Correct. Basically, we are using this for the request pipeline. There
are also other ways.
Now, for example, you have an API project, and you want to add an output cache
in the ASP.NET Core API action method.
How will you add the output cache at the action method level in ASP.NET Core?
Answer:
In ASP.NET Core, we use the ResponseCache attribute over action methods in
APIs. We specify parameters like Duration (e.g., one minute), VaryByQueryKeys,
and other optional parameters.
Statement:
Okay, correct.
Now, have you worked on RabbitMQ?
Answer:
Yeah, I have.
Statement:
Would you please give me a little definition of what RabbitMQ is?
Answer:
RabbitMQ is a message broker used for message queuing. It is an open-source
message broker that helps reduce load and delivery time of a web application
when some resources take a lot of time to process data.
Statement:
Okay, today I have just uploaded a very short video on my channel. I just
explained in an animation type of way how RabbitMQ works. After the interview,
you can watch the video for your own purpose if you want. I have explained it in
an animation way within 30 seconds.
Answer:
Yeah, yeah. I haven't gone through the video yet, but I will definitely check it out.
Statement:
Oh, as you said that you have worked on RabbitMQ in .NET Core applications, I
will move towards the next question.
In .NET Core, we are mostly using dependency injection to avoid tight coupling of
classes.
Would you please tell me a little about what dependency injection is?
Answer:
Yeah, dependency injection—basically, before that, if we want to reduce the
dependencies of objects and achieve low coupling or loose coupling in our
application, we use different approaches like IoC (Inversion of Control) or similar
patterns.
Dependency injection is used to achieve loose coupling in our application,
and .NET Core has built-in dependency injection support.
Statement:
Okay, yeah, correct.
What are the three ways to register my classes in the Startup.cs file in .NET
Core applications?
Answer:
You are asking about Transient, Scoped, and Singleton.
Statement:
Okay, correct. We can register our services and interface classes using the
Singleton, Scoped, and Transient lifetimes.
Now, what are the action verbs in APIs?
Answer:
Action verbs are PUT, POST, GET, and PATCH.
Statement:
Okay, you already gave me four names, which was my next question. Thank you.
Now, for authorization in APIs, you know we are using JWT and OAuth and other
mechanisms.
There are three parts of the JWT token. What data is in the last part?
Answer:
The last part is the Signature. The three parts are Header, Payload, and
Signature.
Statement:
Yes, correct. The last part contains the Signature.
Now, in APIs, versioning is very important, especially when moving to a new
version while maintaining the older ones.
How do you handle the versioning of APIs in .NET Core projects or even in older
versions like ASP.NET MVC 4.7?
Answer:
We can handle API versioning using:
1. Header versioning
2. Query string versioning
3. URI versioning (like /v1/ or /v2/)
Statement:
Okay, correct.
Now, are you using Docker in your projects for deployment?
Answer:
Yeah, of course.
Statement:
Can you explain a little about what Docker is and why we use it?
Answer:
Docker is a complete package that helps create, deploy, and run applications
using containers.
It is portable—once created, the container can run in different environments,
making it highly useful for consistency and scalability.
Statement:
Thank you so much, Ifan. I think we are done from my side. The conversation
was very fruitful with you.
Thank you so much.
Answer:
Thank you, sir. Thank you so much. Nice to talk with you.
1. How do you store a string value in session in ASP.NET and .NET Core?
ASP.NET Framework:
In ASP.NET Framework, sessions are stored using the
HttpContext.Current.Session object.
Code Example:
csharp
CopyEdit
// Storing a string value in session
HttpContext.Current.Session["username"] = "JohnDoe";

// Retrieving the value from session


string username = HttpContext.Current.Session["username"].ToString();
ASP.NET Core:
In .NET Core, session storage is managed using the ISession interface and the
SetString and GetString methods.
Code Example:
csharp
CopyEdit
// Storing a string value in session
HttpContext.Session.SetString("username", "JohnDoe");

// Retrieving the value from session


string username = HttpContext.Session.GetString("username");

2. How do you handle file uploads in .NET Core?


In .NET Core, file uploads are handled using the IFormFile interface in controller
actions.
Code Example:
csharp
CopyEdit
[HttpPost]
public async Task<IActionResult> UploadFile(IFormFile file)
{
if (file != null && file.Length > 0)
{
var filePath = Path.Combine("uploads", file.FileName);
using (var stream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(stream);
}
return Ok("File uploaded successfully!");
}
return BadRequest("No file uploaded.");
}

3. What is Middleware in .NET Core? How do you create custom


middleware?
Middleware is software that handles HTTP requests and responses during the
request pipeline. It performs tasks like authentication, logging, and exception
handling.
Creating Custom Middleware:
1. Create a middleware class.
2. Implement the InvokeAsync method.
3. Use the middleware in the request pipeline.
Code Example:
csharp
CopyEdit
public class IdentifyIranMiddleware
{
private readonly RequestDelegate _next;

public IdentifyIranMiddleware(RequestDelegate next)


{
_next = next;
}

public async Task InvokeAsync(HttpContext context)


{
if (context.Request.Path.Value.Contains("Iran"))
{
await context.Response.WriteAsync("Keyword 'Iran' detected in URL!");
return;
}
await _next(context); // Pass the request to the next middleware
}
}

// Adding middleware to the pipeline


public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMiddleware<IdentifyIranMiddleware>();
}

4. What is Dependency Injection (DI) in .NET Core?


Dependency Injection (DI) is a technique that helps achieve loose coupling by
injecting dependencies rather than creating them directly inside classes.
It improves testability, maintainability, and modularity.
Types of DI:
1. Transient: Created each time they are requested.
2. Scoped: Created once per request.
3. Singleton: Created only once and shared throughout the application.
Code Example:
csharp
CopyEdit
// Service Interface
public interface IMyService
{
string GetMessage();
}

// Service Implementation
public class MyService : IMyService
{
public string GetMessage() => "Hello from MyService!";
}

// Registering services
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IMyService, MyService>(); // Transient registration
}

5. What is RabbitMQ and how is it used in .NET Core?


RabbitMQ is an open-source message broker used to handle asynchronous
messaging between microservices. It is commonly used for message queuing
and supports multiple messaging protocols.
Why use RabbitMQ?
 To reduce load on services.
 To enable asynchronous communication.
 To achieve reliable message delivery.
Code Example:
Producer (Sending a Message):
csharp
CopyEdit
var factory = new ConnectionFactory() { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.QueueDeclare(queue: "myQueue", durable: false, exclusive: false,
autoDelete: false);
string message = "Hello, RabbitMQ!";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "", routingKey: "myQueue", body: body);
Console.WriteLine(" [x] Sent {0}", message);

6. What is JWT (JSON Web Token)? What are its parts?


JWT is a secure way to transmit information as a JSON object. It’s widely used for
authentication and authorization.
Parts of a JWT:
1. Header: Metadata about the token (e.g., type and signing algorithm).
2. Payload: Contains claims or data.
3. Signature: Ensures the integrity of the token.
Example Token:
CopyEdit
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IkpvaG5Eb2UifQ.SflKxw
RJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

7. How to implement API Versioning in .NET Core?


API Versioning helps manage breaking changes and maintain backward
compatibility.
Ways to Implement Versioning:
1. URL Versioning: api/v1/products
2. Query String Versioning: api/products?version=1.0
3. Header Versioning: Using custom headers.
Code Example:
csharp
CopyEdit
services.AddApiVersioning(options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
options.ReportApiVersions = true;
});

8. What are Action Verbs in Web API?


Action verbs indicate the type of HTTP request and specify the action to be
performed. Common action verbs are:
 GET: Retrieve data from the server.
 POST: Submit new data to the server.
 PUT: Update existing data.
 DELETE: Remove data.
 PATCH: Partially update existing data.
Code Example:
csharp
CopyEdit
[HttpGet]
public IActionResult GetData() => Ok("GET request");

[HttpPost]
public IActionResult CreateData() => Ok("POST request");

9. What is Docker and why do we use it?


Docker is a platform that allows applications to be packaged into containers.
Containers are lightweight, portable, and run consistently across different
environments.
Benefits:
 Portability
 Isolation
 Easy Deployment
 Scalability
Dockerfile Example:
dockerfile
CopyEdit
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "MyApp.dll"]

You might also like