1. Introducing c# || C# 10 Flashcards
What are the paradigms of object-oriented programming?
- Encapsulation
- Inheritance
- Polymorphism
What does encapsulation means?
Encapsulation means creating a
boundary around an object to separate its external (public) behavior from its internal (private) implementation details.
What are the distinctive features of C# from an object-oriented perspective?
Name 5
- Unified type system (C# has a unified type system in which all types ultimately
share a common base type i.e. an instance of any type can be converted to a string
by calling its ToString method) - Classes and interfaces
- Properties, methods and events
- Functions can be treated as values (Using delegates, C# allows functions to be passed as values to and from other
functions) - C# supports patterns for purity
What is an interface?
An interface is like a class that cannot hold data. This means that it can define only behavior (and not state), which allows for multiple inheritance as well as a separation between specification and implementation.
What is a ‘type-safety’? Is C# a type safe-language?
instances of types can interact only through protocols they define, thereby ensuring each type’s internal consistency. C# supports static typing, meaning that the language enforces type safety at compile time
C# IS a type safe-language
What is a ‘strongly typed language’ ?
Type rules are strictly enforced (whether statically or at runtime), therefore you cannot call a function that’s designed to accept integer with a floating point number, unless you first EXPLICITLY convert the floating point to an integer ( int x = (int)3.14)
How do you understand a ‘memory management’ in C#?
The Common Language Runtime has a garbage collector that executes as part of your program, reclaiming memory for objects that are no longer referenced. This frees programmers from explicitly deallocating the memory for an object, eliminating the problem of incorrect pointers
C# does not eliminate pointers: it merely makes them unnecessary for most programming tasks. For performance-critical hotspots and interoperability, pointers and explicit memory allocation is permitted in blocks that are marked unsafe.
What is a CLR? Why is it called ‘common’?
A Common Language Runtime (CLR) - provides essential runtime services such as:
1. Automatic memory management
2. Exeption handling
The word “common” means that the same runtime can be shared by other managed programming languages such as F#, Visual Studio…)
How source code gets understood by the native machine? What is the process?
C# (as managed language) compiles source code into managed code (Intermediate Language, IL). CLR converts IL into native code of the machine (i.e. X64 or X86). This is done usually just before execution and called Just-In-Time (JIT) compilation.
What is an ‘assembly’?
In C#, an assembly is a compiled unit of code that contains one or more types, such as classes, interfaces, structs, and enums, along with their associated metadata and resources. An assembly can be thought of as a packaged and self-contained unit of code that can be loaded and executed by the .NET runtime environment.
In .NET, there are two types of assemblies: executable (.exe) and library (.dll) assemblies. Executable assemblies are intended to be executed as standalone applications, while library assemblies are intended to be used by other applications as shared libraries.
An assembly can be created using a compiler, such as the C# compiler, and can be stored as a file on disk or in memory. When an assembly is loaded, the .NET runtime reads the metadata and resources from the assembly and uses it to create an instance of the types defined in the assembly.
Assemblies provide several benefits, including:
Code reuse: Assemblies can be shared across multiple applications, which allows developers to reuse code and reduce development time.
Versioning: Assemblies have a version number, which allows developers to maintain multiple versions of the same assembly, and enables applications to specify which version of an assembly to use.
Security: Assemblies can be digitally signed and their contents can be encrypted, which helps ensure that the code has not been tampered with and that only authorized applications can access the code.
Deployment: Assemblies can be easily deployed by copying the assembly file to the target machine or by installing the assembly into the global assembly cache (GAC).
In summary, an assembly is a compiled unit of code in C# that contains types, metadata, and resources, and can be loaded and executed by the .NET runtime environment. Assemblies provide code reuse, versioning, security, and deployment benefits.
What does reflection do?
With reflection program can query its own metadata
What is BCL?
Base class library (BCL) provides core functionality to programmers, such as collections, input/output, text processing, XML/JSON handling, networking, encryption, interop, concurrency, and parallel programming.
BCL also implements types that the C# language itself requires (for feature such as enumeration, quering, and asynchrony) and lets you explicitly access features of the CLR such as reflection and memory management.
What is a ‘runtime’?
A runtime (also called framework) is a deployable unit that you download and install. A runtime consists of CLR (with its BCL), plus an optional application layer specific to the kind of application that you’re writting - web, mobile, rich client, etc.
When you’re writting an application, you target a particular runtime, which means that your application uses and depends on the functionality that the runtime provides.
What is a .NET 6?
.NET 6 is Microsoft’s flagship open-source runtime. You can write web and console applications that run on Windows, Linux and macOS; rich-client applications that run Windows7 through 11 and macOS; and mobile apps that run on iOS and Andoid.
What is a positional pattern?
In C# positional pattern matching is used to determine, whether or not a deconstructed variable, usually contained in a struct, matches a user-defined nested pattern. The Deconstruct()
method is used to split a variable, such as the tuple into two or more independent variables