.NET Core and C# Programming Basics
62 Questions
0 Views

.NET Core and C# Programming Basics

Created by
@IntelligentCaricature

Podcast Beta

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following is a key feature of.NET Core?

  • It is open-source and cost-free (correct)
  • It is a paid framework
  • It only supports Windows
  • It is not cross-platform
  • The primary usage of an EXE file is to serve as a dynamic link library.

    False

    What does OOPS stand for in programming?

    Object-Oriented Programming System

    .NET Framework is developed by _____ and provides an environment to run and debug applications.

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

    Match the following C# access modifiers with their descriptions:

    <p>public = Accessible from any code private = Accessible only within its own class protected = Accessible within its own class and by derived class instances internal = Accessible within the same assembly</p> Signup and view all the answers

    What is the purpose of a garbage collector in .NET?

    <p>To manage memory automatically</p> Signup and view all the answers

    Method overloading and method overriding are the same concepts.

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

    What are SOLID Principles?

    <p>Design principles intended to make software designs more understandable, flexible, and maintainable.</p> Signup and view all the answers

    What is the primary aim of method overriding in object-oriented programming?

    <p>To provide a specific implementation of a method defined in a superclass</p> Signup and view all the answers

    In ASP.NET Core, a singleton service is created each time it is requested.

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

    What principle states that a software module should have only one reason to change?

    <p>Single Responsibility Principle</p> Signup and view all the answers

    In dependency injection, a __________ service is created once per request.

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

    Match the type of access modifier to its level of accessibility:

    <p>public = Accessible from any class private = Accessible only within the same class protected = Accessible within the same class and derived classes internal = Accessible only within the same assembly</p> Signup and view all the answers

    Which SOLID principle encourages defining small interfaces based on specific submodules?

    <p>Interface Segregation Principle</p> Signup and view all the answers

    Middleware in ASP.NET Core is responsible for handling responses but not requests.

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

    What is the purpose of garbage collection in .NET?

    <p>To manage memory and ensure efficient resource utilization</p> Signup and view all the answers

    Which type of cookie in ASP.NET remains on the user's computer even after the browser is closed?

    <p>Persistent Cookie</p> Signup and view all the answers

    In C#, boxing is the process of converting a value type into a __________ type.

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

    In .NET, Dispose is automatically called by the garbage collector.

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

    Which of the following is not a method of dependency injection in ASP.NET Core?

    <p>Class Injection</p> Signup and view all the answers

    What is the main responsibility of a View Controller in the MVC architecture?

    <p>Managing the user interface and user interactions.</p> Signup and view all the answers

    The Liskov Substitution Principle allows derived classes to modify the behavior of their parent classes.

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

    What are the three main service lifetimes in ASP.NET Core Dependency Injection?

    <p>Singleton, Transient, Scoped</p> Signup and view all the answers

    Session cookies are deleted once the user closes the ______.

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

    Match the following types of caching in .NET with their descriptions:

    <p>In-Memory Caching = Stores data in the memory of the server for quick access Distributed Caching = Stores data across multiple servers to ensure availability Output Caching = Stores the dynamic output of pages for faster retrieval Data Caching = Caches frequently accessed data from databases</p> Signup and view all the answers

    The __________ exception in .NET is derived from the System.Exception class.

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

    Match the description to the corresponding lifetime type in ASP.NET Core:

    <p>Singleton = Shared throughout the application's lifetime Transient = New instance for each request Scoped = Same instance per request Private = Accessible only within the same class</p> Signup and view all the answers

    Which SQL command is used to remove all records from a table but keep the table structure intact?

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

    APIs are primarily used to manage user interface components.

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

    What is the main difference between Dispose and Finalize?

    <p>Dispose is called explicitly, while Finalize is called by the garbage collector.</p> Signup and view all the answers

    Caching in .NET improves application ______ and scalability.

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

    What is the purpose of functions in ASP.NET?

    <p>To simplify complex expressions</p> Signup and view all the answers

    What does the 'sealed' keyword indicate about a class?

    <p>The class cannot be inherited by other classes.</p> Signup and view all the answers

    The using keyword can be used in .NET to ensure Dispose() is called even if an exception occurs.

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

    What are generics in C#?

    <p>Generics are a way to create code that can be used with different data types.</p> Signup and view all the answers

    Entity Framework is an ORM framework that allows developers to interact with a __________ as a set of objects.

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

    What is the primary purpose of a stored procedure?

    <p>To encapsulate frequently performed tasks.</p> Signup and view all the answers

    EF Core is generally considered less flexible than traditional ADO.NET.

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

    Name two characteristics of asynchronous programming in ASP.NET Core.

    <p>Multiple operations run concurrently; frees the main thread.</p> Signup and view all the answers

    A __________ is a reusable set of SQL statements that can accept parameters and return a value or a table variable.

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

    Match the following terms with their definitions:

    <p>Delegate = Object that safely encapsulates a method View = Virtual table generated as the result of a SELECT query IIS = Web server created by Microsoft for hosting applications Const = Value that cannot be changed after its initial declaration</p> Signup and view all the answers

    Which keyword is used to declare an asynchronous method in C#?

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

    Kestrel is a cross-platform web server used primarily for ASP.NET applications.

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

    What distinguishes LINQ from Entity Framework?

    <p>LINQ provides one-to-one mapping between the database table and class.</p> Signup and view all the answers

    Synchronous programming blocks further execution until the current task is _______.

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

    What does the 'dynamic' type allow in C#?

    <p>Dynamic binding at runtime</p> Signup and view all the answers

    In traditional ADO.NET, database operations are usually more abstracted compared to Entity Framework.

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

    What is the primary advantage of using .NET Core over .NET Framework?

    <p>It is open-source and cross-platform</p> Signup and view all the answers

    An EXE file can be shared and used by multiple applications.

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

    What is a stored procedure in SQL?

    <p>A stored procedure is a set of precompiled SQL statements that can be executed as a single unit.</p> Signup and view all the answers

    In ASP.NET, a cookie that is stored on the client side and is persistent is referred to as a ______ cookie.

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

    Match the following programming concepts with their definitions:

    <p>Encapsulation = Bundling of data and methods into a single unit Polymorphism = Methods acting differently based on the object Inheritance = Deriving a new class from an existing class Abstraction = Hiding complex implementation details</p> Signup and view all the answers

    Which component in the .NET framework is responsible for converting CIL into machine code?

    <p>Just-In-Time (JIT) compiler</p> Signup and view all the answers

    LINQ is more advantageous than EF for data manipulation in .NET applications.

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

    Describe the main difference between Synchronous and Asynchronous programming.

    <p>Synchronous programming executes tasks one after another, while asynchronous programming allows tasks to run concurrently.</p> Signup and view all the answers

    In C#, method overloading allows a class to have multiple methods with the same name but different ______.

    <p>parameter lists</p> Signup and view all the answers

    What is IIS mainly used for?

    <p>Hosting web applications</p> Signup and view all the answers

    The .NET Framework is cross-platform compatible.

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

    What is the primary function of the Entity Framework?

    <p>Entity Framework is an Object-Relational Mapper (ORM) that simplifies database operations in .NET applications.</p> Signup and view all the answers

    Kestrel is a ______ web server designed for ASP.NET Core applications.

    <p>cross-platform</p> Signup and view all the answers

    Match the following SQL operations with their descriptions:

    <p>DELETE = Removes all records from a table DROP = Completely removes a table from the database TRUNCATE = Removes all records but retains the table structure</p> Signup and view all the answers

    What is the purpose of using Delegates in C#?

    <p>To encapsulate method references</p> Signup and view all the answers

    Study Notes

    .NET Framework

    • .NET Framework is developed by Microsoft and allows code execution, debugging, and deployment using object-oriented programming
    • Various languages like C#, Cobol, VB, F#, Perl can be used to write applications
    • It supports services, websites, desktop applications, and more

    .NET Core

    • Newer version of .NET Framework
    • Cross-platform framework that runs on Windows, Linux, and macOS
    • Can be used for applications like mobile, web, IoT, cloud, microservices, machine learning, game, etc.

    Core Concepts

    • .NET framework applications are compiled into Common Intermediate Language (CIL) code
    • CIL code is stored in files known as assemblies, which have .dll or .exe extensions
    • The Common Language Runtime (CLR) takes assemblies and uses Just-In-Time (JIT) compiler to translate CIL into machine code

    .NET vs .NET Framework

    • .NET Core is open-source, cross-platform, and has a modular lightweight runtime. It's focused on modern cloud-based applications and microservices.
    • .NET Framework is Windows-only, has a larger set of libraries, and is focused on traditional desktop applications and web services.

    EXE vs DLL

    • EXE files are executable files that run the application they are designed for, they are typically specific to one application.
    • DLL files are libraries that contain code shared among multiple applications, they encapsulate code that can be hidden and reused.

    MVC

    • Model-View-Controller is a software architectural pattern that separates concerns.
    • The Model represents the data and business logic.
    • The View displays the data for the user.
    • The Controller handles user interactions and updates the Model and View.

    Object Oriented Programming (OOP)

    • The key principles of OOP are encapsulation, abstraction, inheritance, and polymorphism.
    • Encapsulation bundles data and methods into a single unit, restricting direct access to data and providing access through public methods.
    • Abstraction hides complex details and shows only essential features, simplifying programming.
    • Inheritance allows a subclass to inherit methods and properties from a parent class.
    • Polymorphism enables methods to behave differently based on the object, achieved through method overloading and method overriding.

    Method Overloading and Method Overriding

    • Method Overloading is a compile-time polymorphism feature.
    • It enables a class to have multiple methods with the same name but different parameter lists (different types or number of parameters).
    • The correct method is selected at compile-time based on the method signature.
    • Method Overriding is a runtime polymorphism feature.
    • It allows a subclass to provide a specific implementation for a method already defined in its superclass.
    • The overridden method in the subclass must have the same name, return type, and parameters as the method in the superclass.

    Abstraction vs Interface

    • Abstract Class defines a base class that can have incomplete methods and properties.
    • It forces derived classes to implement abstract methods and provide their specific implementation.
    • Interface defines a contract that multiple classes can implement.
    • Interfaces cannot have methods with implementation, only signatures.
    • Classes that implement an interface must provide the implementation for all methods defined.

    SOLID Principles

    • Single Responsibility Principle: Each software module should have only one reason to change.
    • Open-Closed Principle: A software module/class should be open for extension but closed for modification.
    • Liskov Substitution Principle: Derived classes should be substitutable for their base classes without affecting the behavior of the parent class.
    • Interface Segregation Principle: Clients should not be forced to implement interfaces they don't use.
    • Dependency Inversion Principle: High-level modules should not depend on low-level modules, instead, both should depend on abstractions.

    Dependency Injection

    • Dependency Injection (DI) is a design pattern that encourages loosely coupled and testable code.
    • It promotes the separation of code concerns by injecting dependent classes into a class at runtime.
    • ASP.NET Core provides a built-in dependency injection container for managing dependencies.

    Service Lifetimes

    • Singleton: A single instance is created for the entire application lifespan.
    • Transient: Creates a new instance for each request.
    • Scoped: Creates a new instance for each scope (generally a web request).

    Middleware

    • Middleware in ASP.NET Core processes requests and responses.
    • It allows developers to modify or extend the request/response pipeline based on specific conditions and logic.
    • It can be used for authentication, authorization, logging, error handling, and much more.

    Middleware vs Filters

    • Middleware operates on requests and responses and applies logic to the entire request pipeline.
    • Filters focus on specific actions or controllers in ASP.NET Core, allowing for action-level filtering.

    Exceptions

    • Exceptions are runtime errors or unexpected events encountered during the execution of code.
    • The try, catch, and finally blocks provide a structured way to handle these exceptions.
    • The throw keyword allows you to manually raise an exception.

    Value Type vs Reference Type

    • Value Type: Stores the data directly in the variable, copies the data when assigned to another.
    • Reference Type: Stores a reference to the data in the variable, shares the same data when assigned to another.

    Boxing and Unboxing

    • Boxing: Converting a value type to a reference type.
    • Unboxing: Converting a reference type back to a value type.

    The Garbage Collector

    • The garbage collector automatically reclaims unused memory in .NET to improve performance.
    • Memory is managed in generations, with more recently allocated objects being more likely to be garbage collected.
    • Garbage collection can be triggered manually or automatically based on memory usage and generational thresholds.

    Authentication and Authorization

    • Authentication validates user identities to determine if a user is who they claim to be.
    • Authorization determines the permissions based on the authenticated user's identity.
    • ASP.NET Core provides various mechanisms for both:
      • Cookies: Small pieces of data stored on the client's computer to identify the user.
      • JSON Web Token (JWT): A standard for securely transmitting information between parties as a JSON object.
      • OpenID Connect: An authentication layer built on top of OAuth 2.0 that provides a standard for signing in and authenticating users.

    IEnumerable, ICollection, IList, IQueryable

    • IEnumerable: Defines an interface for iterating over a sequence of elements.
    • ICollection: Extends IEnumerable and introduces methods for adding, removing, and checking the count of elements.
    • IList: Extends ICollection and provides indexing capabilities for accessing elements by their position.
    • IQueryable: Represents an object that can be used to query data from a data source, enabling complex filtering, sorting, and projection operations.

    C# Access Modifiers

    • public: Code accessible from anywhere.
    • private: Code accessible only within the same class.
    • protected: Code accessible within the same class or classes that inherit from it.
    • internal: Code accessible only within the same assembly (a set of code compiled together).

    var vs dynamic

    • var: Allows the compiler to infer the type of a variable at compile time.
    • dynamic: Delays type checking until runtime, allowing for more flexible but potentially less predictable behavior.

    const, readonly and static

    • const: Initialized once at compile time and cannot be changed.
    • readonly: Initialized once, either at compile time or in the constructor, cannot be changed after that.
    • static: Belongs to the class, not an instance, shared amongst all instances of the class.

    Using Keyword

    • using: Used to include namespaces, making their members available in the current scope.
    • Also used in using blocks to dispose of resources (like files, connections) to prevent memory leaks.

    Generics

    • Generics enable code re-use by using type parameters that can be specified at runtime.
    • They allow developers to work with a variety of data types without writing repetitive code.

    Delegates

    • Delegates represent references to methods - they are like function pointers.
    • They allow developers to pass methods as arguments to other methods, enabling more flexible and dynamic code.
    • They can also be used for events, providing a standard way for objects to signal occurrences.

    Entity Framework (EF)

    • Entity Framework is an Object-Relational Mapper (ORM) framework that simplifies interaction with relational databases (like SQL Server).
    • It allows developers to treat database tables as .NET objects using classes and properties.
    • Two main approaches to using EF are Database-First and Code-First.
      • Database-First: You start with an existing database, and EF creates the entity classes.
      • Code-First: You start by defining entity classes, and EF creates the corresponding database tables.

    Advantages of EF Core over ADO.NET

    • EF Core (a newer version of EF) is lightweight, faster, and more efficient.
    • EF Core works seamlessly with dependency injection.
    • EF Core offers a more modern and intuitive approach to working with databases.

    Advantages of LINQ over EF

    • LINQ (Language Integrated Query) can be used with any data source (including in-memory objects, XML, and databases).
    • EF relies on LINQ for querying data from relational databases.
    • LINQ provides a more flexible and expressive way to write queries than traditional SQL.

    throw vs throw ex

    • throw: Re-raises the current exception, preserving the original stack trace.
    • throw ex: Re-raises the exception, but without the original stack trace.

    IIS

    • Internet Information Services (IIS) is a Web server developed by Microsoft for hosting web applications, especially .NET applications.
    • It is responsible for handling request and response interactions with clients.

    Kestrel

    • Kestrel is a lightweight and cross-platform Web server used in ASP.NET Core applications.
    • It can be used directly on a server (without IIS).

    Kestrel vs IIS

    • IIS runs on Windows, is robust, and provides features like authentication and authorization.
    • Kestrel is cross-platform, lightweight, and more performant, it's the default in ASP.NET Core.

    Synchronous vs Asynchronous Programming

    • Synchronous: Operations are executed sequentially, one after another.
    • Asynchronous: Operations can run concurrently, allowing for greater responsiveness and efficiency.

    Stored Procedure, View, and Function

    • Stored Procedure: Precompiled SQL statements and procedural logic stored in the database.
    • View: A virtual table based on a stored SELECT query, used for data abstraction and security.
    • Function: A reusable set of SQL statements that accept parameters and return a value or table variable.

    Primary Key vs Unique Key

    • Primary Key: A unique identifier for each row in a table.
    • Unique Key: Ensures that the values in one or more columns are unique within the table. A table can have more than one unique key.

    DELETE, DROP, and TRUNCATE

    • DELETE: Removes rows from a table that meet certain criteria.
    • DROP: Removes a table, including its data and structure.
    • TRUNCATE: Removes all data from a table, without affecting its structure.

    Cookies in ASP.NET

    • Session Cookies: Stored in the browser's memory and valid until the user closes the window.
    • Persistent Cookies: Saved on the user's computer and can be set to expire after a certain time period.

    View Controller vs APIs

    • View Controller: A controller in MVC that handles actions that render views (HTML) in a web application.
    • API (Application Programming Interface): Interfaces that expose data and logic to be used by other applications or systems through protocols like HTTP.

    Caching in ASP.NET

    • Caching is a technique for improving performance by storing frequently accessed data in memory.
    • It enables faster retrieval of data without needing to access the underlying source (like a database).

    Dispose and Finallize

    • Dispose: Invoked manually to free up resources (like files or network connections) to prevent leaks.
    • Finalize: Automatically called by the garbage collector (generally when the garbage collector determines an object is no longer reachable). It's used for cleaning up unmanaged resources.

    Functions in SQL

    • Encapsulate common computations or transformations
    • Used in calculations, data transformations, and queries
    • Accept input parameters, perform operations, and return values

    Primary Key vs. Unique Key in SQL

    • Primary Key - Uniquely identifies each row in a table
    • Unique Key - Ensures uniqueness of a column or combination of columns, but doesn't necessarily identify rows

    DELETE, DROP, and TRUNCATE in SQL

    • DELETE - Removes rows from a table
    • DROP - Removes an entire table, including data and schema
    • TRUNCATE - Removes data from a table without deleting the table itself

    Types of Cookies in ASP.NET

    • Persistent Cookies - Stored on the user's computer and persist after the browser is closed.
    • Session Cookies - Stored in memory and expire when the browser closes.

    View Controller vs. APIs in ASP.NET

    • View Controller - Manages the user interface, interacts with the user, and updates the view.
    • APIs - Allow different software systems to communicate over the internet via HTTP requests.

    Caching in .NET

    • Improves application performance by storing frequently accessed data in temporary storage.
    • Reduces the need to repeatedly fetch data from slow sources.
    • In-Memory Caching - Stores data in the application's memory.
    • Distributed Caching - Stores data across multiple servers to improve scalability.

    Dispose and Finalize in .NET

    • Dispose - Explicitly releases unmanaged resources and cleans up operations.
    • Finalize - Releases unmanaged resources before garbage collection.
    • Dispose is called manually by developers, while Finalize is called by the garbage collector.

    Studying That Suits You

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

    Quiz Team

    Description

    Test your knowledge on the key features of .NET Core and foundational concepts of C# programming. This quiz covers topics like OOP principles, access modifiers, and garbage collection. Challenge yourself to see how well you understand these critical programming concepts!

    More Like This

    Web Programming and ASP
    10 questions

    Web Programming and ASP

    TrustedRainforest avatar
    TrustedRainforest
    EF Core and ORM Techniques in ASP.NET Core
    15 questions
    Web Programming using .NET Unit 2
    40 questions
    Use Quizgecko on...
    Browser
    Browser