1. Introducing c# || C# 10 Flashcards

1
Q

What are the paradigms of object-oriented programming?

A
  1. Encapsulation
  2. Inheritance
  3. Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does encapsulation means?

A

Encapsulation means creating a
boundary around an object to separate its external (public) behavior from its internal (private) implementation details.

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

What are the distinctive features of C# from an object-oriented perspective?

Name 5

A
  1. 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)
  2. Classes and interfaces
  3. Properties, methods and events
  4. Functions can be treated as values (Using delegates, C# allows functions to be passed as values to and from other
    functions)
  5. C# supports patterns for purity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an interface?

A

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.

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

What is a ‘type-safety’? Is C# a type safe-language?

A

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

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

What is a ‘strongly typed language’ ?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you understand a ‘memory management’ in C#?

A

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.

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

What is a CLR? Why is it called ‘common’?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How source code gets understood by the native machine? What is the process?

A

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.

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

What is an ‘assembly’?

A

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.

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

What does reflection do?

A

With reflection program can query its own metadata

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

What is BCL?

A

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.

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

What is a ‘runtime’?

A

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.

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

What is a .NET 6?

A

.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.

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

What is a positional pattern?

A

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

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

What is a property pattern?

A

Property patterns let you match on an objects properties. You can use it both in switches and with the ‘is’ operator. This example uses a property pattern to test whether obj is a string with a length of 4:
if (obj is string {Length: 4}) ...

17
Q

What is ‘nullable reference type’?

A

Nullable reference type bring a degree of non-nullability to reference types, with the purpose of helping to avoid NullReferenceExeption. Nullable reference types introduce a level of safety that’s enforced purely by the compiler in the form of warnings or errors when it detects code that’s at risk of generating a NullReferenceExeption.

string? myNumber = null;

18
Q

What is a Local Method?

A

A local method is a method declared within another function. They are visible only inside the containing function:

void WriteCubes()
{
  Console.WriteLine(Cube (3));

  int Cube (int value) => value * value * value;
}
19
Q

What is a deconstructor?

A

Deconstructor assigns fields back to a set of variables

20
Q

What is LINQ?

A

Language-Integrated Query enables queries to be written directly within c# program and checked statically for correctness and query both local collections or remote data sources

21
Q

What are Lambda Expressions?

A

Lambda Expressions are miniature functions created by the compiler on the fly.

22
Q

What is an Extension method?

A

Extension methods extend an existing type with new methods (without altering the types definition), making static methods feel like instance methods. LINQ’s query operators are implemented as extension methods.