.NET and C# Interview Questions
40 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the primary function of the Common Language Runtime (CLR) in the .NET framework?

  • To interact with the operating system directly
  • To compile C# code into machine code
  • To optimize the performance of .NET applications
  • To provide services like memory management, security, and exception handling (correct)
  • What is the difference between managed and unmanaged code in .NET?

  • Managed code is faster than unmanaged code
  • Managed code is executed by the CLR, while unmanaged code is executed by the operating system (correct)
  • Managed code is executed by the operating system, while unmanaged code is executed by the CLR
  • Managed code is used for web applications, while unmanaged code is used for desktop applications
  • What is the process called when the CLR converts Intermediate Language (IL) code into native machine code?

  • Static Compilation
  • Dynamic Linking
  • Ahead-of-Time (AOT) compilation
  • Just-In-Time (JIT) compilation (correct)
  • What are the two categories of data types in C#?

    <p>Value and Reference</p> Signup and view all the answers

    What is .NET used for?

    <p>Building a wide variety of applications, including web, mobile, desktop, and gaming</p> Signup and view all the answers

    What is the main benefit of using the IDisposable interface and the using statement in .NET?

    <p>Providing a robust pattern for resource management</p> Signup and view all the answers

    What is the primary advantage of using async/await in .NET?

    <p>Improving application responsiveness</p> Signup and view all the answers

    What is the main advantage of using Entity Framework in .NET?

    <p>Providing a high-level abstraction over database connections</p> Signup and view all the answers

    What is the purpose of the Join method in .NET threading?

    <p>To wait for the background thread to complete</p> Signup and view all the answers

    What is the main benefit of using threading in .NET?

    <p>Improving application performance and efficiency</p> Signup and view all the answers

    What is the primary mechanism of memory management in .NET applications?

    <p>Garbage Collector (GC)</p> Signup and view all the answers

    What is the main benefit of using LINQ in C#?

    <p>Strongly typed, compile-time checking, and support for IntelliSense</p> Signup and view all the answers

    What is the purpose of delegates in C#?

    <p>To allow methods to be passed as parameters, stored in variables, and returned by other methods</p> Signup and view all the answers

    What is the difference between abstract classes and interfaces in C#?

    <p>Abstract classes provide a default implementation, while interfaces define a contract</p> Signup and view all the answers

    What is an example of dynamic polymorphism in C#?

    <p>Method overriding</p> Signup and view all the answers

    What is the purpose of Garbage Collection (GC) in .NET?

    <p>To reclaim memory used by objects that are no longer accessible</p> Signup and view all the answers

    What is the primary purpose of attributes in C#?

    <p>To add declarative information to program elements</p> Signup and view all the answers

    What is the result of the .NET compilation process?

    <p>Platform-independent Intermediate Language (IL) and then platform-specific machine code</p> Signup and view all the answers

    What is the purpose of the Global Assembly Cache (GAC)?

    <p>To store shared .NET assemblies with strong names</p> Signup and view all the answers

    What is the focus of .NET 5 and onwards?

    <p>To unify the .NET Framework and .NET Core platforms under a single .NET runtime and framework</p> Signup and view all the answers

    How can attributes be used in C#?

    <p>To add metadata to program elements</p> Signup and view all the answers

    What is the role of the .NET Compiler Platform?

    <p>To convert high-level code into platform-independent Intermediate Language (IL)</p> Signup and view all the answers

    What is the importance of understanding the compilation process in .NET?

    <p>It is crucial for grasping how .NET applications are built, deployed, and executed</p> Signup and view all the answers

    What is a common use case for attributes in C#?

    <p>Data validation in ASP.NET Core models</p> Signup and view all the answers

    What is the significance of strong names in the Global Assembly Cache (GAC)?

    <p>They are unique identifiers for shared .NET assemblies</p> Signup and view all the answers

    What is the primary benefit of using middleware in ASP.NET Core?

    <p>To provide a modular and reusable way to process requests</p> Signup and view all the answers

    What is the main purpose of Dependency Injection in .NET Core?

    <p>To facilitate loose coupling between software components</p> Signup and view all the answers

    What is the goal of the .NET Standard?

    <p>To establish greater uniformity in the .NET ecosystem</p> Signup and view all the answers

    What is the benefit of targeting the .NET Standard in a class library project?

    <p>It allows the library to run on any .NET platform that supports the targeted .NET Standard</p> Signup and view all the answers

    What is the primary purpose of garbage collection in .NET?

    <p>To eliminate memory leaks and other memory-related errors</p> Signup and view all the answers

    What is the primary advantage of using ASP.NET Core middleware?

    <p>It allows for precise control over how requests are processed</p> Signup and view all the answers

    Which of the following is NOT a phase of the garbage collection process?

    <p>Initializing</p> Signup and view all the answers

    What is the primary purpose of encapsulation in object-oriented programming?

    <p>To protect an object's internal state from unauthorized access and modification</p> Signup and view all the answers

    What is polymorphism in object-oriented programming?

    <p>Treating objects as instances of their parent class</p> Signup and view all the answers

    What is the purpose of a namespace in C#?

    <p>All of the above</p> Signup and view all the answers

    What is the primary benefit of using extension methods in C#?

    <p>To add new functionality to existing types without modifying them</p> Signup and view all the answers

    How should exceptions be handled in asynchronous programming with C#?

    <p>By inspecting the task object after it has completed</p> Signup and view all the answers

    What is the primary use of reflection in .NET?

    <p>To inspect and invoke methods of a class dynamically</p> Signup and view all the answers

    What is the main purpose of middleware in ASP.NET Core?

    <p>To customize the request pipeline in an application</p> Signup and view all the answers

    What is a characteristic of extension methods in C#?

    <p>They must be defined in a static class</p> Signup and view all the answers

    Study Notes

    .NET and C# Overview

    • .NET is a comprehensive development platform for building various applications, including web, mobile, desktop, and gaming.
    • .NET supports multiple programming languages, such as C#, F#, and Visual Basic.
    • The .NET Framework Class Library (FCL) provides a large class library, and the Common Language Runtime (CLR) offers services like memory management, security, and exception handling.

    Common Language Runtime (CLR)

    • The CLR is a virtual machine component of the .NET framework that manages the execution of .NET programs.
    • It provides services like memory management, type safety, exception handling, garbage collection, and thread management.
    • The CLR converts Intermediate Language (IL) code into native machine code through Just-In-Time (JIT) compilation.

    Managed and Unmanaged Code

    • Managed code is executed by the CLR, which provides services like garbage collection, exception handling, and type checking.
    • Unmanaged code, on the other hand, is executed directly by the operating system, and all memory allocation, type safety, and security must be handled by the programmer.

    C# Basics

    • A basic C# program consists of elements such as namespaces, classes, methods, and variables.
    • Data types in C# are divided into two categories: Value Types and Reference Types.
    • Value types are stored in the stack, while reference types are stored in the heap.

    Garbage Collection

    • Garbage collection (GC) in .NET is an automatic memory management feature that frees up memory used by objects that are no longer accessible in the program.
    • The GC operates on a separate thread and works in three phases: marking, relocating, and compacting.

    Exception Handling

    • Exception handling in C# is a mechanism to handle runtime errors, allowing a program to continue running or fail gracefully instead of crashing.
    • It is done using the try, catch, and finally blocks.

    Classes and Object-Oriented Programming

    • Classes can be categorized based on their functionality and accessibility.
    • Encapsulation is a fundamental principle of object-oriented programming (OOP) that involves bundling the data and methods that operate on the data into a single unit.
    • Polymorphism is a core concept in OOP that allows objects to be treated as instances of their parent class rather than their actual derived class.

    Delegates

    • Delegates in C# are type-safe function pointers or references to methods with a specific parameter list and return type.
    • They allow methods to be passed as parameters, stored in variables, and returned by other methods.

    LINQ

    • LINQ (Language Integrated Query) is a powerful feature in C# that allows developers to write expressive, readable code to query and manipulate data.
    • It provides a uniform way to query various data sources, such as collections in memory, databases, and XML documents.

    Abstract Classes and Interfaces

    • Both abstract classes and interfaces are types that enable polymorphism, allowing objects of different classes to be treated as objects of a common super class.
    • However, they serve different purposes and have different rules.

    Memory Management

    • Memory management in .NET applications is primarily handled automatically by the Garbage Collector (GC).
    • Understanding and cooperating with the GC can help improve your application's performance and memory usage.

    Threading

    • Threading in .NET allows for the execution of multiple operations simultaneously within the same process.
    • It enables applications to perform background tasks, UI responsiveness, and parallel computations, improving overall application performance and efficiency.

    Async and Await

    • Async and await are keywords that simplify writing asynchronous code, making it more readable and maintainable.
    • The async modifier indicates that a method is asynchronous and may contain one or more await expressions.

    Entity Framework

    • Entity Framework (EF) is an open-source object-relational mapping (ORM) framework for .NET.
    • It enables developers to work with databases using .NET objects, eliminating the need for most of the data-access code.

    Extension Methods

    • Extension methods in C# allow developers to add new methods to existing types without modifying, deriving from, or recompiling the original types.
    • They provide a flexible way to extend the functionality of a class or interface.

    Exception Handling in Tasks

    • When a method returns a Task or Task, exceptions should be handled within the task to avoid unhandled exceptions that can crash the application.
    • Exceptions thrown in a task are captured and placed on the returned task object.

    Reflection

    • Reflection in .NET is a powerful feature that allows runtime inspection of assemblies, types, and their members.
    • It enables creating instances of types, invoking methods, and accessing fields and properties dynamically, without knowing the types at compile time.

    Middleware

    • Middleware in ASP.NET Core is software that's assembled into an application pipeline to handle requests and responses.
    • Each component in the middleware pipeline is responsible for invoking the next component in the sequence or short-circuiting the chain if necessary.

    Dependency Injection

    • Dependency Injection (DI) is a design pattern that facilitates loose coupling between software components by removing the direct dependencies among them.

    • In .NET Core, DI is used to manage object creation and inject dependencies where required, making the code more modular, easier to test, maintain, and extend.### Dependency Injection in .NET Core

    • A foundational feature that supports the development of decoupled and easily testable applications.

    .NET Standard

    • A formal specification of .NET APIs that are intended to be available on all .NET implementations.
    • Enables developers to create libraries that are compatible across different .NET platforms with a single codebase.
    • Versioned, with each version building upon the previous one and adding more APIs.
    • Higher versions of the .NET Standard support newer APIs but reduce the number of platforms that support that standard.

    Targeting .NET Standard in a Class Library

    • The class library targets .NET Standard 2.0, meaning it can run on any .NET platform that supports .NET Standard 2.0 or higher.
    • Makes the library highly reusable across a wide range of applications and platforms.

    .NET Ecosystem

    • .NET Core, .NET Framework, and Xamarin are all part of the .NET ecosystem.
    • They serve different purposes and are used in different types of projects.
    • .NET 5 and onwards aim to unify these platforms under a single .NET runtime and framework.

    Garbage Collection (GC) in .NET

    • An automatic memory management feature that helps in reclaiming the memory used by objects that are no longer accessible in the application.
    • Eliminates the need for manual memory management, reducing the risks of memory leaks and other memory-related issues.
    • Can be optimized to improve applications' performance and reliability.

    Attributes in C#

    • A powerful way to add declarative information to your code.
    • Used to add metadata, such as compiler instructions, annotations, or custom information, to program elements.
    • Can influence the behavior of certain components at runtime or compile time, and can be queried through reflection.
    • Can be used for data validation in ASP.NET Core models.

    Custom Attributes

    • Can be defined for specific needs.
    • Can be attached to classes or methods, providing custom descriptive metadata.
    • The AttributeUsage attribute specifies where this attribute can be applied and whether it can be used multiple times on the same element.

    Code Compilation in .NET

    • Involves converting high-level code into a platform-independent Intermediate Language (IL) and then into platform-specific machine code.
    • Facilitated by the .NET Compiler Platform ("Roslyn" for C# and Visual Basic) and the Common Language Runtime (CLR).
    • Involves multiple steps, including parsing, syntax analysis, and IL generation.

    Global Assembly Cache (GAC)

    • A machine-wide code cache for the Common Language Runtime (CLR) in the .NET Framework.
    • Stores assemblies specifically designated to be shared by several applications on the computer.
    • Used to store shared .NET assemblies that have strong names.
    • Can be used to add an assembly to the GAC using the gacutil tool.

    Securing a Web Application in ASP.NET Core

    • Involves implementing a series of best practices and utilizing built-in security features.
    • Strategies to consider include enabling HTTPS redirection, using authentication and authorization, and validating user input.
    • Securing an ASP.NET Core web application is a comprehensive process that involves multiple layers of defense.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Assess your knowledge of .NET and C# with these 50 technical interview questions, designed for candidates of varying expertise levels.

    More Like This

    C# Properties
    10 questions

    C# Properties

    DiversifiedConstructivism avatar
    DiversifiedConstructivism
    C# Inheritance and Interfaces
    10 questions
    C# Files and Data Hierarchy
    20 questions
    Use Quizgecko on...
    Browser
    Browser