C# Flashcards

1
Q

What is a class?

A

A class is an encapsulation of attributes and methods used to represent an entity.

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

What is an object?

A

An object is an instance of a class, stored in memory.

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

What are the fundamental OOP concepts?

A

Encapsulation, Abstraction, Inheritance, Polymorphism. (EAIP)

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

What is Encapsulation in OOP?

A

The ability to define private attributes and methods on a class. This then allows us if we wish, to hide the internal representation/information about an object, from the outside world. Setters & getters are required to access the internal data.

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

What is Abstraction in OOP?

A

The concept of moving focus from the concrete implementation of things, to the types of things (classes) and operations available (methods). This allows us to make programming simpler and more abstract. For example, we can have an abstract Animal class which Dog & Cat implement from. Let the programmer focus on Animal rather than Dog or Cat specifics.

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

What is Inheritance in OOP?

A

The ability to create new classes from another class by modifying and extending the behaviour of the parent class. For example, Dog & Cat can inherit from an Animal class and we can extend the Dog class with a Woof() method.

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

What is Polymorphism in OOP?

A

The ability to have multiple methods with same name, but different implementations.

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

What is C#?

A

C# is an object-oriented, type-safe language that is compiled by the .NET framework. The .NET framework provides a run-time environment called the Common Language Runtime (CLR) which runs the code.

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

Important features of C#?

A
  • It is an OOP strongly-typed language.
  • It is type safe, meaning it doesn’t allow unsafe casts like converting a double to a Boolean.
  • It can be used to develop console applications, windows applications and web applications.
  • With .NET Core, it can now be used to write applications that are cross-platform.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the CLR?

A

The Common Language Runtime (CLR) is a run-time environment which runs C#/.NET code. It compiles it down to intermediate language, therefore making C#, managed code. It contains Garbage Collection (GC): Responsible for automatic memory management.

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

What is unmanaged code?

A

Code that is executed by any runtime other than .NET. The ‘other’ runtime will take care of memory, security and other operations.

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

Can multiple catch blocks be executed?

A

No. Once an exception has been caught and a single catch block is executed, it then moves to the finally block.

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

What is the use of ‘using’ statements in C#?

A

Once the code within the using statement has been executed to obtain a resource, it is then automatically disposed of. e.g. Dapper/IDbConnection to close the connection. This uses IDisposable in the background and calls .Dispose() on it.

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

What is a Jagged Array?

A

A Jagged Array is an array whose elements, are arrays.

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

What is the difference between an Array and an ArrayList?

A

Arrays have a fixed size, ArrayList’s are dynamic.

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

What is the difference between String and StringBuilder?

A

String is immutable so when we modify it, a new instance is created in memory. StringBuilder however is mutable so the same string in memory is modified.

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

What is the difference between public, static and void?

A

Public declared variables or methods are accessible anywhere within the application. Static is the same except can be called without an object instantiation. Void is a type modifier that a method does not return any value.

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

What are sealed classes in C#? What are sealed methods or properties in C#?

A

When a class is sealed, it prevents other classes inheriting from it.

Using sealed on a method or property in a class will allow other classes to derive from the class but prevent them being overridden.

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

What is an interface class? Give an example.

A
An interface is an abstract class which defines the contract of a class. It contains declaration of public methods to satisfy the contract. If a class implements an interface, it must abide by that contract.
An example is: IVehicle, Car : IVehicle, Boat : IVehicle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the difference between an interface & abstract class?

A

Interfaces are just contracts and contain no definition or implementations of public methods. Abstract classes meanwhile can have concrete implementations of methods along with private methods.

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

Give an example of using an abstract class.

A
abstract class FourLeggedAnimal -> string Describe() { return “I am a four legged animal” }
Dog : FourLeggedAnimal -> Dog.Describe(); // inherits the implementation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is method overloading?

A

When we create multiple methods with the same name, but different parameter options.

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

Can private methods be overridden?

A

No as they are not visible outside the scope of their class.

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

What is the difference between private and protected?

A

Private variables or methods cannot be accessed by child classes, only internally. Protected variables & methods are accessible by both child classes & interally.

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

What is the difference between a ref parameter & an out parameter?

A

A ref parameter must be initialised prior to being passed to a method. An out parameter needs not.

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

Can we use ‘this’ in a static method?

A

No because we can only use static variables and methods in a static method.

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

What is the difference between const and readonly?

A

Constant variables are declared and initialised at compile time where the value cannot then be changed without recompilation. Read Only variables within a class meanwhile can be changed, but only via a constructor during runtime.

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

What is the difference between a value type and a reference type?

A

An integer is a value type as it holds a data value in its own memory space. A string is a reference type as it holds a reference/pointer to a different memory space where data is stored.

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

What is a protected class/method/variable?

A

Protected means something is only visible to itself & derived/child classes.

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

What is serialization?

A

When we want to transport an object through a network, we convert it into a stream of bytes to send. For an object to be serializable, it must implement ISerialize. Types of serialization include JSON serialization, XML serialization, SOAP or Binary serialization.

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

What is a virtual method? Give an example.

A
Virtual allows you to indicate that a method or property can be overridden within a derived class.
abstract class FourLeggedAnimal -> virtual string Describe() { return “I am a four legged animal” }
Dog : FourLeggedAnimal -> string Describe() { return “Woof” } -> Dog.Describe(); // overridden
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What are circular references/dependencies?

A

When two or more resources/packages depend on each other. Since one can not be compiled without the other, this makes both unusable until the circular references are resolved.

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

What are generics in C#?

A

Generics are used to decrease code redundancy, increase type safety and performance. For example, new List();

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

What are delegates in C#?

A

Like C++ function pointers, a delegate is a variable that references a potential method. It can be passed as a parameter to another method and used to trigger that method.

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

What is a multicast delegate?

A

A delegate that has multiple handlers assigned to it.

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

What is the difference between a Struct and a Class?

A

Structs are value-type whilst Classes are reference-types. Structs store their attributes on a stack, whilst Classes store their attributes on a Heap. All members of a struct are public by default, whilst all members of a class are private by default. Structs do not support inheritance. As structs are value-type, there is no need for the Garbage Collection to deal with them.

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

What is the Singleton Pattern and how can you implement it in C#?

A
A singleton is a class which only allows a single instance of itself to be created.
public sealed class Singleton {
	private static readonly Singleton _instance = new Singleton();
	private Singleton() {}
	public static Singleton Instance { get { return _instance; }}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What is the difference between a Singleton class and a Static class?

A

A static class cannot be extended, whereas a singleton can.

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

What are the different types of DI?

A

Transient: A new instance of an object for every specific code request.
Scoped: The same single object for every web request.
Singleton: The same single object used throughout, by everything.

40
Q

What is the difference between throw and throw ex?

A

Using throw ex in a catch, will throw a new exception object with the stack trace reset to the method that caused it. Using throw, throws the exact same exception object that was caught, preserving the original stack trace.

41
Q

Explain Reflection in C#

A

Reflection is the ability to access metadata of code during runtime. This allows us to test the type of an object or properties or methods on an object during runtime.

42
Q

Explain pooling such as object pooling or thread pooling.

A

Thread pooling is the process of creating a collection of threads in multithreaded applications and then reusing those threads for new tasks when required, instead of creating new threads. When a thread is run and is completed, it is returned to the thread pool to be used again later. Same for objects.

43
Q

Why do we use Async and Await in C#?

A

The async and await keywords allow us to create asynchronous methods. Asynchronous methods will run independently of the main application thread and reduce blocking. Despite this, async and await tasks do not run on their own threads as they are IO bound tasks.

44
Q

What is a Race Condition in C#?

A

When two threads try to access the same resource and change it simultaneously. It is impossible to predict which thread manages to succeed in accessing or modifying the resource.

45
Q

What is a Deadlock in C#?

A

When a process is not able to complete its execution because two or more processes in a multi-threading application are waiting for each other to finish.

46
Q

What does internal mean in C#?

A

Internal types or members are accessible only within files in the same assembly.

47
Q

What does private mean in C#?

A

Private types or members are accessibly only within the same class or struct they are declared in.

48
Q

What does protected mean in C#?

A

Protected members can be accessed only in the same class or a derived/child class. Private members cannot.

49
Q

What does public mean in C#?

A

Public types or members have no restrictions and can be accessed from anywhere.

50
Q

What does protected internal mean in C#?

A

Protected internal can be accessed only within the same assembly OR by a derived class in another assembly.

51
Q

What does private protected mean in C#?

A

Private protected can be accessed only by a derived class in the same assembly.

52
Q

What does abstract mean in C#?

A

Something that is abstract, indicates it is missing or incomplete. An abstract class is like an interface with some implementations, but needs to be derived to be “completed”. An abstract variable must be assigned in the child/derived class.

53
Q

What does async mean in C#?

A

If a method is async, it is asynchronous. Often used on controllers and return a Task type.

54
Q

What does override mean in C#?

A

Override is used when overriding the implementation of an extended method.

55
Q

What does virtual mean in C#?

A

If a method is virtual, it means it can be overridden from a derived class. You cannot use virtual with static, abstract, private or override.

56
Q

What does namespace mean in C#?

A

A namespace is a scope that contains a set of related objects.

57
Q

What is a SQL Join?

A

Combines records from two separate tables.

58
Q

LEFT JOIN?

A

Venn Diagram: (A)(B)
Selects A & Intersection.

SELECT * FROM TableA a
LEFT JOIN TableB b
ON a.Key = b.Key

59
Q

RIGHT JOIN?

A

Venn Diagram: (A)(B)
Selects B & Intersection.

SELECT * FROM TableA a
RIGHT JOIN TableB b
ON a.Key = b.Key

60
Q

FULL OUTER JOIN?

A

Venn Diagram: (A)(B)
A & Intersection & B

SELECT * FROM TableA a
FULL OUTER JOIN TableB b
ON a.Key = b.Key

61
Q

INNER JOIN?

A

Venn Diagram: (A)(B)
Only Intersection

SELECT * FROM TableA a
INNER JOIN TableB b
ON a.Key = b.Key

62
Q

What is boxing in C#?

A

It is the process of converting a value type in to a reference type. Unboxing is vice versa.

63
Q

What is LINQ?

A

LINQ is Language-Integrated Query. It is a microsoft model, that allows an expressive syntax of querying and manipulating data in C#.

64
Q

What does JWT stand for?

A

JSON Web Tokens

65
Q

What are JWT tokens?

A

An industry standard method for authentication between two parties.

66
Q

What are the 3 parts of a JWT token?

A

Header, Payload (contains claims) & Verify Signature

67
Q

Explain the JWT process?

A

Token is created and signed with a secret. Server knows that secret and can use it to verify JWT signature by decoding it and finds out the user id claim.

68
Q

What happens when you enter “google.com” in to the browser?

A

DNS (domain name) -> TCP (transmission control protocol) to build connection between browser and server with google on it -> Browser sends HTTP request -> Server sends HTTP response back to browser.

69
Q

What does OWASP stand for?

A

Open Web Application Security Project

70
Q

What is SQL injection?

A

A code injection technique that aims to destroy your database. E.g. Submit “DROP ALL” to a server, hope it appends it to the end of a SELECT query.

71
Q

What is XSS?

A

Cross-Site Scripting (XSS) are a malicious type of injection where scripts are injected in to websites to be run and cause havoc. The script could be inserted at the end of a URL as a phishing link or submitted, stored in a database and then it is loaded on pages for all users when being “displayed”.

72
Q

How to prevent XSS?

A

Sanitize inputs to not allow scripts. HTTPOnly flag so javascript cannot access cookies.

73
Q

What is CSRF?

A

Cross-Site Request Forgery (CSRF) is where an attacker fakes a form/post request to abuse a victims logged in cookie. They create a fake webpage that does a POST request for a bank transfer. The bank thinks it’s the real user because they’re logged in to the bank. This can be prevented by using a CSRF token.

74
Q

How to prevent CSRF?

A

Double Submit Cookie Method - Server generates CSRF token every time a form is generated. Submits the CSRF token with every request. The CSRF token is impossible for an attacker to guess and will confirm a request is coming from the real website. A fake POST attack, won’t go through as the hacker cannot guess the right CSRF token.

75
Q

Black Box Testing?

A

Testing from outside in, with no knowledge about software implementations.

76
Q

White Box Testing?

A

Testing from the inside with knowledge about software implementations such as unit testing.

77
Q

What are the SOLID Principles?

A
Single Responsibility Principle
Open/Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion
78
Q

What is the S in the SOLID Principles? Describe it.

A
Single Responsibility Principle.
A class should have one and only one responsibility.
79
Q

What is the O in the SOLID Principles? Describe it.

A

Open/Closed Principle.
Design classes, to be extended & overridden for change. Rather than have to be modified internally for every requirements change.

80
Q

What is the L in the SOLID Principles? Describe it.

A
Liskov Substitution Principle.
Any child class of a parent class, can be used in place of its parent class without leading to unexpected behaviour.
e.g.
public class Bird { void fly() }
public class Duck extends Bird{}
public class Ostrich extends Bird{}

A duck can fly. An ostrich cannot and therefore has an empty fly() implementation. If we replace an instance of Duck, with Ostrich in our code, then we break LSP because our code will work differently.

81
Q

What is the I in the SOLID Principles? Describe it.

A

Interface Segregation Principle.

A client should not be forced to depend on any interfaces, that they do not use.

82
Q

What is the D in the SOLID Principles? Describe it.

A

Dependency Inversion.
Entities must depend on abstractions rather than concrete implementations.

e.g. ILogger vs. Logger

83
Q

Name some Patterns?

A

Repository Pattern, Factory Pattern, Builder Pattern, Command Pattern.

84
Q

SQL vs. NoSQL

A

SQL: Relational (save space), Prevents Duplication, Best suits Transactional based applications, Complex querying of data.
NoSQL: Speed, Easier to use for devs, Flexible schema.

85
Q

What is ACID?

A

Atomicity - Each transaction is a single unit.
Consistency - Each transaction only contains valid actions.
Isolation - Concurrent transactions leave the DB in the same state as if they were executed sequentially.
Durability - Once a transaction has been committed, it remains committed even in case of system failure.

86
Q

Difference between Mocks and Stubs/Fakes?

A

Mock - Object that registers received calls and allows us to confirm just that specific calls have been received.

Fake - Object with working implementations, but not same as production (e.g. In Memory DB).

Stub - Object with working implementations, set to return pre-defined data (e.g. x.ThenReturn(y)).

87
Q

MVC vs. MVVM?

A

MVC - Model View Controller:
Allows decoupling of view to the backend.
Controller mediates between view & data model.
Allows front-end devs & back-end devs to work simultaneously without worrying about each other.

MVVM - Model View ViewModel:
Where we use two-way data binding between the View (HTML/JSX) and a ViewModel (Vue, React, AngularJS).
ViewModel on front-end then contains business logic instead of a controller on the back-end.

88
Q

What is Continuous Integration/Continuous Delivery?

A

With each code change, an automated build and test sequence is triggered. Aiming to minimise friction & time to deploy by automating steps taken to be safe to deploy and ready.

89
Q

What is Continuous Deployment?

A

When deployments occur automatically whenever a major change is made to the code.

90
Q

What are Microservices?

A

Independently deployable and autonomous services that work together, modelled around a business domain.

91
Q

Steps of Event Storming?

A
  • Identify Domain Events
  • Distinguish Commands & Actors of Events
  • Define Aggregates
  • Group Aggregates for Bounded Contexts
92
Q

What is Eventual Consistency?

A

A type of system where transactions may not apply/be present in all databases immediately. An example is Twitter. Not everyone may see the tweet at once. Not catastrophic if that happens due to Eventual Consistency.

93
Q

Name types of tests on the Testing Pyramid

A

End to End Tests
Integration Tests
Acceptance Tests
Unit Tests

94
Q

What Protocol to use for Messaging Apps? (P2P)

A

XMPP

95
Q

What is a Database Index and why use it?

A

Data Structure to improve the speed of data retrieval operations on a database table.

96
Q

Name some HTTP Methods & what they do

A

GET - Used to get data
POST - Used to send data in the request body
PUT - Used when updating data, send the whole data object to change
DELETE - Used when deleting data
PATCH - Used when updating data, send only the data we want changed