.NET Core interview questions and answers 👇
What are some characteristics of .NET Core?↑
- Flexible deployment: Can be included in your app or installed side-by-side user- or machine-wide.
- Cross-platform: Runs on Windows, macOS and Linux; can be ported to other OSes. The supported Operating Systems (OS), CPUs and application scenarios will grow over time, provided by Microsoft, other companies, and individuals.
- Command-line tools: All product scenarios can be exercised at the command-line.
- Compatible: .NET Core is compatible with .NET Framework, Xamarin and Mono, via the .NET Standard Library.
- Open source: The .NET Core platform is open source, using MIT and Apache 2 licenses. Documentation is licensed under CC-BY. .NET Core is a .NET Foundation project.
- Supported by Microsoft: .NET Core is supported by Microsoft, per .NET Core Support
What is CTS?↑
The Common Type System (CTS) standardizes the data types of all programming languages using .NET under the umbrella of .NET to a common data type for easy and smooth communication among these .NET languages. CTS is designed as a singly rooted object hierarchy with System.Object as the base type from which all other types are derived. CTS supports two different kinds of types:
- Value Types: Contain the values that need to be stored directly on the stack or allocated inline in a structure. They can be built-in (standard primitive types), user-defined (defined in source code) or enumerations (sets of enumerated values that are represented by labels but stored as a numeric type).
- Reference Types: Store a reference to the value‘s memory address and are allocated on the heap. Reference types can be any of the pointer types, interface types or self-describing types (arrays and class types such as user-defined classes, boxed value types and delegates).
What is Zero Garbage Collectors?↑
Zero Garbage Collectors is the simplest possible implementation that in fact does almost nothing. It only allows you to allocate objects because this is obviously required by the Execution Engine. Created objects are never automatically deleted and theoretically, no longer needed memory is never reclaimed.
Explain a simple GC implementation?↑
It is an excellent basis for the development of your own Garbage Collection mechanism. It provides the necessary functionality to make runtime work properly and you can build on top of that.
It may be interesting for special use cases like very short living applications or such that almost no allocate memory (you can come up with those concepts as No-alloc or Zero-alloc programming). In such a case providing GC overhead is unnecessary and it may be wise to get rid of it. It is like making huge GC.TryStartNoGCRegion overall your application.
When does Garbage collection occur?↑
Garbage collection occurs when one of the following conditions is true.
- The system has low physical memory.
- The memory that is used by allocated objects on the managed heap surpasses an acceptable threshold. This threshold is continuously adjusted as the process runs.
- The GC.Collect method is called and in almost all cases, you do not have to call this method, because the garbage collector runs continuously. This method is primarily used for unique situations and testing.
What is CoreFx?↑
CoreFx is the reimplementation of the class libraries for .NET Core.
What is unit testing?↑
Unit testing is a development process for the software that has the smallest testable parts of an application, which are called units. They are individually and independently scrutinized for any proper operation. Unit testing is can either be automated or done manually as well.
What are Empty migrations?↑
Sometimes it's useful to add a migration without making any model changes. In this case, adding a new migration creates code files with empty classes. You can customize this migration to perform operations that don't directly relate to the EF Core model. Some things you might want to manage this way are:
- Full-Text Search
- Stored procedures
Differences Between .net Core and .net Framework?↑
The differences between the two can be summarized in these three points:
NuGet-based: .NET Core is distributed as a set of NuGet packages that allow app-local deployments. In contrast, the .NET-Framework is always installed in a system-wide location. This difference doesn’t matter so much for class libraries, but it matters for applications as those are expected to deploy the closure of their dependencies. But we expect this model to change how quickly class library authors can take advantage of new functionality. Since the applications can simply deploy a new version (as opposed to having to wait until a given .NET Framework version is widely adopted), there is less of a penalty for component authors to take advantage of the latest features.
Well layered: .NET Core was specifically designed to be layered. The goal was to create a .NET stack that can accommodate a wide variety of capabilities and system constraints without forcing customers to recompile their binaries and/or produce new assets. This means that we had to remove certain APIs because they tied lower-level components to higher-level components. In those cases, we provide alternatives, often in the form of extension methods.
Free of problematic tech: .NET Core doesn’t include certain technologies we decided to discontinue because we found them to be problematic, for instance, AppDomain and sandboxing. If the scenario still makes sense for .NET Core, our plan is to have replacements. For example, AssemblyLoadContext replaces AppDomains for loading and isolating assemblies.
What are complex and supporting methods?↑
- The System.Numerics.Complex type represents a complex number, i.e., a number with a real number part and an imaginary number part
- It supports a standard set of arithmetic, comparison, equality, explicit conversion, and implicit conversion operators, as well as mathematical, algebraic, and trigonometric methods.
What is FCL?↑
Framework Class Libraries (FCL)- The Framework class library (FCL) is a comprehensive collection of reusable types including classes, interfaces and data types included in the .NET-Framework to provide access to system functionality.
What is IGCToCLR interface?↑
This interface passed as an argument to the function InitializeGarbageCollector is used to communicate with the runtime. It contains quite a lot of available methods and listing them all here is pointless.
What is Modularity?↑
Modularity leads to performance benefits and your application can run faster, especially ASP.NET Core application.
Defines the types and methods of a class library?↑
- A class the library defines the types and methods that can be called from any application.
- A class the library developed using .NET Core supports the .NET Standard Library, which allows your library to be called by any .NET platform that supports that a version of the .NET Standard Library.
- When you finish your class library, you can decide whether you want to distribute it as a third-party component, or whether you want to include it as a component that is bundled with one or more applications.
What are the Fundamental Libraries?↑
Fundamental Libraries − A set of framework libraries, which provide primitive data types, app composition types and fundamental utilities.
What are Generate SQL scripts in .Net core?↑
When debugging your migrations or deploying them to a production database, it's useful to generate a SQL script. The script can then be further reviewed for accuracy and tuned to fit the needs of a production database. The script can also be used in conjunction with a deployment technology.
Explain the difference between Task and Thread in .NET↑
Thread represents an actual OS-level thread, with its own stack and kernel resources. Thread allows the highest degree of control; you can Abort() or Suspend() or Resume() a thread, you can observe its state, and you can set thread-level properties like the stack size, apartment state, or culture. ThreadPool is a wrapper around a pool of threads maintained by the CLR.
The Task class from the Task Parallel Library offers the best of both worlds. Like the ThreadPool, a task does not create its own OS thread. Instead, tasks are executed by a TaskScheduler; the default scheduler simply runs on the ThreadPool. Unlike the ThreadPool, Task also allows you to find out when it finishes, and (via the generic Task) to return a result.
When should we use .NET Core and .NET Standard Class Library project types?↑
Use a .NET Standard library when you want to increase the number of apps that will be compatible with your library, and you are okay with a decrease in the .NET API surface area your library can access.
Use a .NET Core library when you want to increase the .NET API surface area your library can access, and you are okay with allowing only .NET Core apps to be compatible with your library.
What are the advantages that you could speak about Web API?↑
Content Negotiation, routing, and model bindings are some of the top picks that one could say when it comes to the advantages of Web API.
What is meant by Web API routing?↑
It is a pattern matching routine that is similar to what is found in MVC architecture. Route Tables contain all the routes that have been registered.
Briefly explain exception filters.↑
Exceptions that are thrown but are not handled will lead to the execution of exception filters. IExceptionFilter interface is implemented by the exception filters.
Explain the difference between a class and an object.↑
In short, a class is the definition of an object, and an object is instance of a class.
We can look at the class as a template of the object: it describes all the properties, methods, states and behaviors that the implementing object will have. As mentioned, an object is an instance of a class, and a class does not become an object until it is instantiated. There can be more instances of objects based on the one class, each with different properties.
LINQ is an acronym for Language Integrated Query, and was introduced with Visual Studio 2008. LINQ is a set of features that extends query capabilities to the .NET language syntax by adding sets of new standard query operators that allow data manipulation, regardless of the data source. Supported data sources are: .NET Framework collections, SQL Server databases, ADO.NET Datasets, XML documents, and any collection of objects that support IEnumerable or the generic IEnumerable
Explain the difference between the Stack and the Heap.↑
The short answer would be: in the Stack are stored value types (types inherited from System.ValueType), and in the Heap are stored reference types (types inherited from System.Object).
We can say the Stack is responsible for keeping track of what is actually executing and where each executing thread is (each thread has its own Stack). The Heap, on the other hand, is responsible for keeping track of the data, or more precise objects.
What is a delegate in .NET?↑
A delegate in .NET is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. In addition, we could use delegate to create custom event within a class.
Encapsulation is a function that includes various methods and data within a project. This is done so that the object of the program could perform its functions smoothly and without any errors.
Is there a difference between ‘debug’ and ‘trace’?↑
Yes. The Trace class can be used for debugging and releasing certain builds, while Debug is used solemnly for – you’ve guessed it – debugging.
This can be classified as one of the trick .NET interview questions, for it is quite easy to get forget about Trace’s additional function.
Although this isn’t necessarily one of the primary .NET interview questions, it is still often asked because of how it relates to .NET.
Inheritance happens when one smaller class takes on the features and parameters of another, bigger class. This bigger class is then seen as a “parent class” to the smaller one.
This is also one of the better .NET framework interview questions to expand upon. .NET supports only single inheritance. What this means is that the smaller, child class can only benefit (inherit) from one parent class.
Caching is a process when you keep your most often used files and data in a separate memory. This separate location – a cache – is where you can access all of your designated files. Caching saves developers a lot of time and increases their memory management.
What is a ‘.dll’ file?↑
DLL files are those which need to be hidden out of plain sight. The term directly abbreviates to “Dynamic Link Library”. These libraries are vast, containing a huge amount of files and commands. DLLs can also be shared among other programs and apps. A small piece in .NET interview questions but can make a huge difference.
Can you specify access modifiers in an interface?↑
Assuming that the question relates to the item access modifiers – no, no you can’t. Why? Simply because the interface is always public.
What are advantages of Garbage Collection?↑
Garbage Collection provides the following benefits:
- You don’t need to free the memory manually while developing your application.
- It also allocates objects on the managed heap efficiently.
- When objects are no longer used then it will reclaim those objects by clearing their memory, and keeps the memory available for future allocations.
- Managed objects automatically get clean content to start with, so their constructors do not have to initialize every data field.
- It also provides memory safety by making sure that an object cannot use the content of another object.
What is UWP App in .Net core?↑
UWP apps will be able to use libraries you have created in .net core as long as you target the .netstandard1.6 (or higher) framework moniker. UWP is only for the Windows ecosystem.
What is MSBuild and how it works with .NET Core?↑
MSBuild is the build platform for Microsoft and Visual Studio. In the UWP application if you open the project folder, then you will see both project.json and *.csproj files. But if you open our previous .NET Core Console app, then you will see project.json and *.xproj files.
How does MEF work?↑
It allows application developers to discover and use extensions with no configuration required. MEF is an integral part of the .NET Framework 4 and is available wherever the .NET-Framework is used that improves the flexibility, maintainability, and testability of large applications.