.NET Core Interview Questions by https://www.interviewbit.com/ Flashcards

1
Q

What are Universal Windows Platform(UWP) Apps in .Net Core?

A

Universal Windows Platform(UWP) is one of the methods used to create client applications for Windows. UWP apps will make use of WinRT APIs for providing powerful UI as well as features of advanced asynchronous that are ideal for devices with internet connections.

Features of UWP apps:

  • Secure: UWP apps will specify which resources of device and data are accessed by them.
  • It is possible to use a common API on all devices(that run on Windows 10).
  • It enables us to use the specific capabilities of the device and adapt the user interface(UI) to different device screen sizes, DPI(Dots Per Inches), and resolutions.
  • It is available on the Microsoft Store on all or specified devices that run on Windows 10.
  • We can install and uninstall these apps without any risk to the machine/incurring “machine rot”.
  • Engaging: It uses live tiles, user activities, and push notifications, that interact with the Timeline of Windows as well as with Cortana’s Pick Up Where I Left Off, for engaging users.
  • It can be programmable in C++, C#, Javascript, and Visual Basic. For UI, you can make use of WinUI, HTML, XAML, or DirectX.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write a program to calculate the addition of two numbers.

A

The steps are as follows:

  1. You need to create a new ASP.NET Core Project “CalculateSum”. Open Visual Studio 2015, goto File–> New–> Project. Select the option Web in Left Pane and go for the option ASP.NET Core Web Application (.NET Core) under the central pane. Edit the project name as “CalculateSum” and click on OK.
  2. In the template window, select Web Application and set the Authentication into “No Authentication” and click on OK.
  3. Open “Solution Explorer” and right-click on the folder “Home” (It is Under Views), then click on Add New Item. You need to select MVC View Page Template under ASP.NET Section and rename it as “addition.cshtml” and then click on the Add button.
  4. Open addition.cshtml and write the following code:

```
@{
ViewBag.Title = “Addition Page”;
}

<h1>Welcome to Addition Page</h1>

<form>

<span>Enter First Number : </span> <input></input> <br></br><br></br>
<span>Enter Second Number : </span> <input></input> <br></br><br></br>
<input></input>
</form>

<h2>@ViewBag.Result</h2>

Here, we have created a simple form that is having two text boxes and a single Add Button. The text boxes are named as `txtFirstNum` and `txtSecondNum`. On the controller page, we can access these textboxes using:
`<form asp-controller="Home" asp-action="add" method="post">`

This form will indicate all the submissions will be moved to HomeController and the method add action will be executed.

5. Open the `HomeController.cs` and write the following code onto it:

 ```

using System;
using Microsoft.AspNetCore.Mvc;

namespace CalculateSum.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Application description page.";
            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Contact page.";
            return View();
        }

        public IActionResult Error()
        {
            return View();
        }

        public IActionResult addition()
        {
            return View();
        }

        [HttpPost]
        public IActionResult add()
        {
            int number1 = Convert.ToInt32(HttpContext.Request.Form["txtFirstNum"].ToString());
            int number2 = Convert.ToInt32(HttpContext.Request.Form["txtSecondNum"].ToString());
            int res = number1 + number2;
            ViewBag.Result = res.ToString();
            return View("addition");
        }
    }
}

In this program, we have added two IAction Methods addition() and add(). Addition() method will return the addition view page and add() method obtains input from the browser, processes it, and results will be kept in ViewBag.Result and then returned to the browser.

Now, press Ctrl+F5 for running your program. This will launch an ASP.NET Core website into the browser. Add /Home/addition at the end of the link and then hit on enter.

Conclusion
The .NET is a full-stack software development framework, which is essentially used to build large enterprise-scale and scalable software applications. The .NET framework has wide scope in the market. It is a flexible and user-friendly framework, that goes well along with other technologies.

The .NET Core was developed in response to the surge in Java popularity. The .NET Core is normally used in low-risk projects. Some of the .NET components can be used in .NET core applications (but not the other way around). This article mainly concentrates on the framework concepts of .Net and .NET Core.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain about .NET Core Components.

A

The .NET Core Framework is composed of the following components:

  • CLI Tools: Command Line Interface(CLI) tools is a cross-platform tool for developing, building, executing, restoring packages, and publishing. It is also capable of building Console applications and class libraries that can run on the entire .NET framework. It is installed along with .NET Core SDK for the selected platforms. So it does not require separate installation on the development machine. We can verify for the proper CLI installation by typing dotnet on the command prompt of Windows and then pressing Enter. If usage and help-related texts are displayed, then we can conclude that CLI is installed properly.
  • Roslyn(.NET Compiler platform): It is a set of an open-source language compiler and also has code analysis API for the C# and Visual Basic (VB.NET) programming languages. Roslyn exposes modules for dynamic compilation to Common Intermediate Language(CLI), syntactic (lexical) and semantic code analysis, and also code emission.
  • CoreFX: CoreFX is a set of framework libraries. It consists of the new BCL(Base Class Library) i.e. System.* things like System.Xml, System.Collections, etc.
  • CoreCLR: A JIT(Just In Time) based CLR (Command Language Runtime). CoreCLR is the runtime implementation that runs on cross-platform and has the GC, RyuJIT, native interop, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is middleware in .NET core?

A
  • Middleware is software assembled into an application pipeline for request and response handling. Each component will choose whether the request should be passed to the next component within the pipeline, also it can carry out work before and after the next component within the pipeline.
  • For example, we can have a middleware component for user authentication, another middleware for handling errors, and one more middleware for serving static files like JavaScript files, images, CSS files, etc.
  • It can be built-in into the .NET Core framework, which can be added through NuGet packages. These middleware components are built as part of the configure method’s application startup class. In the ASP.NET Core application, these Configure methods will set up a request processing pipeline. It contains a sequence of request delegates that are called one after another.
  • Normally, each middleware will handle the incoming requests and passes the response to the next middleware for processing. A middleware component can take the decision of not calling the next middleware in the pipeline. This process is known as short-circuiting the pipeline or terminating the request pipeline. This process is very helpful as it avoids unnecessary work. For example, if the request is made for a static file such as a CSS file, image, or JavaScript file, etc., these static files middleware can process and serve the request and thus short-circuit the remaining pipeline.

Here, there are three middlewares are associated with an ASP.NET Core web application. They can be either middleware provided by the framework, added through NuGet, or your own custom middleware. The HTTP request will be added or modified by each middleware and control will be optionally passed to the next middleware and a final response will be generated on the execution of all middleware components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Differentiate .NET Core vs .NET framework.

A

Features of .NET Core & .NET framework

Compatibility

  • .NET Core: It works based on the principle of “build once, run anywhere”. It is cross-platform, so it is compatible with different operating systems such as Linux, Windows, and Mac OS.
  • .NET framework: This framework is compatible with the Windows operating system only. Even though, it was developed for supporting software and applications on all operating systems.

Installation

  • .NET Core: Since it is cross-platform, it is packaged and installed independently of the OS.
  • .NET framework: It is installed in the form of a single package for Windows OS.

Application Models

  • .NET Core: It does not support developing the desktop application and it focuses mainly on the windows mobile, web, and windows store.
  • .NET framework: It is used for developing both desktop and web applications, along with that it also supports windows forms and WPF applications.

Performance and Scalability

  • .NET Core: It provides high performance and scalability.
  • .NET framework: It is less effective compared to .Net Core in terms of performance as well as scalability of applications.

Support for Micro-Services and REST Services

  • .NET Core: It supports developing and implementing the micro-services and the user is required to create a REST API for its implementation.
  • .NET framework: It does not support the microservices’ development and implementation, but it supports REST API services.

Packaging and Shipping

  • .NET Core: It is shipped as a collection of Nugget packages.
  • .NET framework: All the libraries that belong to the .Net Framework are packaged and shipped all at once.

Android Development

  • .NET Core: It is compatible with open-source mobile app platforms like Xamarin, via .NET Standard Library. Developers can make use of tools of Xamarin for configuring the mobile application for particular mobile devices like Android, iOS, and Windows phones.
  • .NET framework: It does not support the development of mobile applications.

CLI Tools

  • .NET Core: For all supported platforms, it provides lightweight editors along with command-line tools.
  • .NET framework: This framework is heavy for CLI(Command Line Interface) and developers usually prefer to work on the lightweight CLI.

Deployment Model

  • .NET Core: Updated version of the .NET Core gets initiated on one machine at a time, which means it gets updated in new folders/directories in the existing application without affecting it. Thus, we can say that .NET Core has a very good flexible deployment model.
  • .NET framework: When the updated version is released, it is deployed only on the Internet Information Server at first.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain Explicit Compilation (Ahead Of Time compilation).

A
  • Ahead-of-time(AOT) compilation is the process of compiling a high-level language into a low-level language during build-time, i.e., before program execution. AOT compilation reduces the workload during run time.
  • AOT provides faster start-up time, in larger applications where most of the code executes on startup. But it needs more amount of disk space and memory or virtual address space to hold both IL(Intermediate Language) and precompiled images. In this case, the JIT(Just In Time) Compiler will do a lot of work like disk I/O actions, which are expensive.
  • The explicit compilation will convert the upper-level language into object code on the execution of the program. Ahead of time(AOT) compilers are designed for ensuring whether the CPU will understand line-by-line code before doing any interaction with it.
  • Ahead-of-Time (AOT) compilation happens only once during build time and it does not require shipping the HTML templates and the Angular compiler into the bundle. The source code generated can begin running immediately after it has been downloaded into the browser, earlier steps are not required. The AOT compilation will turn the HTML template into the runnable code fragment. AOT will analyze and compile our templates statically during build time.

Benefits of AOT Compilation:

  • Application size is smaller because the Compiler itself isn’t shipped and unused features can be removed.
  • Template the parse errors that are detected previously(during build time)
  • Security is high (not required to dynamically evaluate templates)
  • Rendering of a component is faster (pre-compiled templates)
  • For AOT compilation, some tools are required to accomplish it automatically in the build process.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is MEF?

A

The MEF(Managed Extensibility Framework) is a library that is useful for developing extensible and lightweight applications. It permits application developers for using extensions without the need for configuration. It also allows extension developers for easier code encapsulation and thus avoiding fragile hard dependencies. MEF will let you reuse the extensions within applications, as well as across the applications. It is an integral part of the .NET Framework 4. It improves the maintainability, flexibility, and testability of large applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In what situations .NET Core and .NET Standard Class Library project types will be used?

A

.NET Core library is used if there is a requirement to increase the surface area of the .NET API which your library will access, and permit only applications of .NET Core to be compatible with your library if you are okay with it.

.NET Standard library will be used in case you need to increase the count of applications that are compatible with your library and reduce surface area(a piece of code that a user can interact with) of the .NET API which your library can access if you are okay with it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is CoreRT?

A
  • CoreRT is the native runtime for the compilation of .NET natively ahead of time and it is a part of the new .NET Native (as announced in April 2014).
  • It is not a virtual machine and it does not have the facility of generating and running the code on the fly as it doesn’t include a JIT. It has the ability for RTTI(run-time type identification) and reflection, along with that it has GC(Garbage Collector).
  • The type system of the CoreRT is designed in such a way that metadata for reflection is not at all required. This feature enables to have an AOT toolchain that can link away unused metadata and can identify unused application code.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is .NET Core SDK?

A

.NET Core SDK is a set of tools and libraries that allows the developer to create a .NET application and library for .NET 5 (also .NET Core) and later versions. It includes the .NET CLI for building applications, .NET libraries and runtime for the purpose of building and running apps, and the dotnet.exe(dotnet executable) that runs CLI commands and runs an application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Docker?

A
  • Docker is an open-source platform for the development of applications, and also for shipping and running them. It allows for separating the application from the infrastructure using containers so that software can be delivered quickly. With Docker, you will be able to manage the infrastructure in the same ways you used to manage your applications.
  • It supports shipping, testing, and deploying application code quickly, thus reducing the delay between code writing and running it in production.
  • The Docker platform provides the ability of packaging and application execution in a loosely isolated environment namely container. The isolation and security permit you for running multiple containers at the same time on a given host. Containers are lightweight and they include every necessary thing required for running an application, so you need not depend on what is currently installed within the host.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Xamarin?

A
  • Xamarin is an open-source platform useful in developing a modern and efficient application for iOS, Android, and Windows with .NET. It is an abstraction layer used to manage the communication of shared code with fundamental platform code.
  • Xamarin runs in a managed environment that gives benefits like garbage collection and memory allocation.
  • Developers can share about 90% of their applications over platforms using Xamarin. This pattern permits developers for writing entire business logic in a single language (or reusing existing app code) but accomplish native performance, look and feel on each platform. The Xamarin applications can be written on Mac or PC and then they will be compiled into native application packages, like a .ipa file on iOS, or .apk file on Android.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can you differentiate ASP.NET Core from .NET Core?

A

.NET Core is a runtime and is used for the execution of an application that is built for it. Whereas ASP.NET Core is a collection of libraries that will form a framework for developing web applications. ASP.NET Core libraries can be used on .NET Core as well as on the “Full .NET Framework”.

An application using the tools and libraries of ASP.NET Core is normally referred to as “ASP.NET Core Application”, which in theory doesn’t say whether it is built for .NET Framework or .NET Core. So an application of “ASP.NET Core” can be considered as a “.NET Core Application” or a “.NET Framework Application”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is MSBuild in the .NET Core?

A

MSBuild is the free and open-source development platform for Visual Studio and Microsoft. It is a build tool that is helpful in automating the software product creation process, along with source code compilation, packaging, testing, deployment, and documentation creation. Using MSBuild, we can build Visual Studio projects and solutions without the need of installing the Visual Studio IDE.

In the Universal Windows Platform(UWP) app, if you open the folder named project, you will get to see both files namely project.json and *.csproj. But if you open our previous Console application in .NET Core, you will get to see project.json and *.xproj files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Whether ‘debug’ and ‘trace’ are the same?

A

No. The Trace class is used for debugging as well as for certain build releases. It gives execution plan and process timing details. While debug is used mainly for debugging. Debug means going through the program code flow during execution time.

Debug and trace allow for monitoring of the application for errors and exceptions without VS.NET IDE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Transfer-encoding?

A

Transfer-encoding is used for transferring the payload body(information part of the data sent in the HTTP message body) to the user. It is a hop-by-hop header, that is applied not to a resource itself, but to a message between two nodes. Each multi-node connection segment can make use of various Transfer-encoding values.

Transfer-encoding is set to “Chunked” specifying that Hypertext Transfer Protocol’s mechanism of Chunked encoding data transfer is initiated in which data will be sent in a form of a series of “chunks”. This is helpful when the amount of data sent to the client is larger and the total size of the response will not be known until the completion of request processing.

17
Q

Give the differences between .NET Core and Mono?

A

.NET Core & Mono

  • .Net Core is the subset of implementation for the .NET framework by Microsoft itself.
  • Mono is the complete implementation of the .Net Framework for Linux, Android, and iOS by Xamarin.
  • .NET Core only permits you to build web applications and console applications.
  • Mono permits you to build different application types available in .NET Framework, including mobile applications, GUI-enabled desktop apps, etc.
  • .NET Core does not have the built-in capability to be compiled into WebAssembly-compatible packages.
  • Mono has the built-in capability to be compiled into WebAssembly-compatible packages.
  • .NET Core is never intended for gaming. You can only develop a text-based adventure or relatively basic browser-based game using .NET Core.
  • Mono is intended for the development of Games. Games can be developed using the Unity gaming engine that supports Mono.
18
Q

Explain about types of Common Type System(CTS).

A

Common Type System(CTS) standardizes all the datatypes that can be used by different programming languages under the .NET framework.

CTS has two types. They are:

  1. Value Types: They contain the values that are stored on a stack or allocated inline within a structure. They are divided into :
    * Built-in Value Types - It includes primitive data types such as Boolean, Byte, Char, Int32, etc.
    * User-defined Value Types - These are defined by the user in the source code. It can be enumeration or structure.
    * Enumerations - It is a set of enumerated values stored in the form of numeric type and are represented by labels.
    * Structures - It defines both data(fields of the structure) and the methods(operations performed on that data) of the structure. In .NET, all primitive data types like Boolean, Byte, Char, DateTime, Decimal, etc., are defined as structures.
  2. Reference Types: It Stores a reference to the memory address of a value and is stored on the heap. They are divided into :
    * Interface types - It is used to implement functionalities such as testing for equality, comparing and sorting, etc.
    * Pointer types - It is a variable that holds the address of another variable.
    * Self-describing types - It is a data type that gives information about themselves for the sake of garbage collectors. It includes arrays(collection of variables with the same datatype stored under a single name) and class types(they define the operations like methods, properties, or events that are performed by an object and the data that the object contains) like user-defined classes, boxed value types, and delegates(used for event handlers and callback functions).
19
Q

What is the use of generating SQL scripts in the .NET core?

A

It’s useful to generate a SQL script, whenever you are trying to debug or deploy your migrations to a production database. The SQL script can be used in the future for reviewing the accuracy of data and tuned to fit the production database requirement.

20
Q

What is the IGCToCLR interface?

A

IGCToCLR interface will be passed as an argument to the InitializeGarbageCollector() function and it is used for runtime communication. It consists of a lot of built-in methods such as RestartEE(), SuspendEE(), etc.

21
Q

What is CoreFx?

A

CoreFX is the set of class library implementations for .NET Core. It includes collection types, console, file systems, XML, JSON, async, etc. It is platform-neutral code, which means it can be shared across all platforms. Platform-neutral code is implemented in the form of a single portable assembly that can be used on all platforms.

22
Q

What is Zero Garbage Collectors?

A

Zero Garbage Collectors allows you for object allocation as this is required by the Execution Engine. Created objects will not get deleted automatically and theoretically, no longer required memory is never reclaimed.

There are two main uses of Zero Garbage Collectors. They are:

  • Using this, you can develop your own Garbage Collection mechanism. It provides the necessary functionalities for properly doing the runtime work.
  • It can be used in special use cases like very short living applications or almost no memory allocation(concepts such as No-alloc or Zero-alloc programming). In these cases, Garbage Collection overhead is not required and it is better to get rid of it.
23
Q

What is the purpose of webHostBuilder()?

A

WebHostBuilder function is used for HTTP pipeline creation through webHostBuilder.Use() chaining all at once with WebHostBuilder.Build() by using the builder pattern. This function is provided by Microsoft.AspNet.Hosting namespace. The Build() method’s purpose is building necessary services and a Microsoft.AspNetCore.Hosting.IWebHost for hosting a web application.

24
Q

What is CoreCLR?

A

CoreCLR is the run-time execution engine provided by the .NET Core. It consists of a JIT compiler, garbage collector, low-level classes, and primitive data types. .NET Core is a modular implementation of .NET, and can be used as the base stack for large scenario types, ranging from console utilities to web applications in the cloud.

Here, various programming languages will be compiled by respective compilers(Roslyn can compile both C# and VB code as it includes C# and VB compilers) and Common Intermediate Language(CIL) code will be generated. When the application execution begins, this CIL code is compiled into native machine code by using a JIT compiler included within CoreCLR. This CoreCLR is supported by many operating systems such as Windows, Linux, etc.

25
Q

What are C# and F#?

A

C# is a general-purpose and object-oriented programming language from Microsoft that runs on the .NET platform. It is designed for CLI(Common Language Infrastructure), which has executable code and a runtime environment that allows for the usage of different high-level languages on various computer platforms and architectures. It is mainly used for developing web applications, desktop applications, mobile applications, database applications, games, etc.

F# is an open-source, functional-first, object-oriented and, cross-platform programming language that runs on a .NET platform and is used for writing robust, succinct, and performant code. We can say that F# is data-oriented because here code involves transforming data with functions. It is mainly used in making scientific models, artificial intelligence research work, mathematical problem solving, financial modelling, GUI games, CPU design, compiler programming, etc.

26
Q

What is Dot NET Core used for?

A
  • .NET Core is useful in the server application creations, that run on various operating systems like Windows, Mac, and Linux. Using this, developers can write libraries as well as applications in C#, F#, and VB.NET in both runtimes.
  • Generally, it is used for cloud applications or for modifying large enterprise applications into microservices.
  • .NET Core 3.0 supports cross-development between WPF, UWP, and Windows Forms.
  • .NET Core supports microservices, which permits cross-platform services to work with the .NET Core framework including services developed with .NET Framework, Ruby, Java, etc.
  • .NET Core’s features like lightweight, modularity, and flexibility make it easier to deploy .NET Core applications in containers. These containers can be deployed on any platform, Linux, cloud, and Windows.
27
Q

What is .NET core?

A

.NET Core can be said as the newer version of the .NET Framework. It is a cost-free, general-purpose, open-source application development platform provided by Microsoft. It is a cross-platform framework because it runs on various operating systems such as Windows, Linux, and macOS. This Framework can be used to develop applications like mobile, web, IoT, machine learning, game, cloud, microservices, etc.

It consists of important features like a cross-platform, sharable library, etc., that are necessary for running a basic .NET Core application. The remaining features are supplied in the form of NuGet packages, that can be added to your application according to your needs. Like this we can say, the .NET Core will boost up the performance of an application, decreases the memory footprint, and becomes easier for maintenance of an application. It follows the modular approach, so instead of the entire .NET Framework installation, your application can install or use only what is required.