.NET CORE Flashcards

1
Q

What is Model Binding (ASP.Net) and why is it important?

A

Model binding is asp.net is essentially the middle man between your incoming http request and your api controller. It is important because it binds the incoming http request with the proper controller action method.

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

What are the fundamentals that a developer should consider when working to wire up model binding correctly?

A

Make sure your routing is correct to whatever the name of your specific service is. The correct interface is being provided in the constructor so that when the api controller is instantiated it has the correct methods that need the logic implemented for. Each service needs to have proper error handling so that errors do not get swallowed, meaning the error doesn’t come back in a response. Proper error handling includes multiple catches such as sqlexception, argumentexception, or exception. Have proper null checks in place so you can return an error that specifies if data isn’t passed in.

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

What are the differences between an API Controller and a “regular/view” Controller in .Net?

A

API controllers are specialized in returning data. Json without serialization. Normal controllers are used to return views.

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

When creating a new controller, what class do you inherit from?

A

The basecontroller or baseAPIcontroller

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

Describe the main differences or considerations between the JS and C#.

A

C# is a static typed language meaning it’s type checking at compile and can’t run without you fixing them. JavaScript is dynamically typed so you can attempt to run it even if you have errors. C# also requires you to define the data type of your variables whereas JavaScript doesn’t.

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

What is the generic name of the library used in .Net that is used to communicate with Databases?

A

ADO.NET. Namespcaes system.data, system.data.SqlClient,

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

What are the .Net objects and classes used to communicate and execute commands at the database?

A

Dbcommand Class.

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

What is a Null Reference Exception?

A

A NullReferenceException is thrown when you try to access a member on a type whose value is null. A NullReferenceException typically reflects developer error and is thrown usually when they have forgotten to instantiate a reference type.

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

What is an MVC View?

A

Model-View-Controller View is a display using the model class object. It is a software class and contains a template and data form to produce a response for the browser.

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

What is a Model?

A

A model represents the shape of data as public properties and business logic as methods. Think of like your USERS or ADDUSERREQUEST.

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

What are C# extension methods?

A

A method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Example: when you implement an interface and can use the methods in it.

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

What are Interfaces?

A

Interfaces are contracts that defines methods or properties that an implementing class must provide implementing logic for.

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

What is an abstract class and is this different than an interface?

A

An abstract class allows you to create functionality that subclasses can implement or override. An interface only allows you to define functionality, not implement it. And whereas a class can extend only one abstract class, it can take advantage of multiple interfaces.

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

Can you create an instance of an abstract class?

A

No you cannot because it does not have a complete implementation. The purpose of an abstract class is to function as a base for subclasses. it acts like a template or an empty structure you should extend and build on it before use.

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

What are the principles of object-oriented programming?

A

Encapsulation - Restricting access to methods and attributes of certain classes (private). Preventing accidental modification of data or unwanted changes. Abstraction - extension of encapsulation, process of selecting data from a larger pool to show only the relevant details to the object. (Only certain data needed to create account on dating app, things such as favorite food or hobbies isn’t needed) Inheritance - the ability for one object to acquire some/all properties of another object. Such as updateUser : addUser Polymorphism - A way to use a class exactly like its parent so there is no confusion with mixing types. Example Testdata has methind add(int a, int b, inc ) returns a + b + C. Another class can take a new version named t = new testdata() then get the method and bring in it’s own parameters. t.add(3 + 5 + 8) returns = 16.

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

What are Generics in .Net

A

Generics let you tailor a method, class, structure, or interface to the precise data type it acts upon. For example, List

17
Q

Why are Generics so important?

A

Performance: Collections that store the objects use boxing and unboxing on data types. A collection can reduce performance. Type Safety: there is no strong type information at compile time as to what is stored in the collection.

18
Q

In .Net how many classes can one class inherit from?

A

You can only inherit from one base class.

19
Q

How do you declare a variable in C#?

A

You would declare a variable like this: DATATYPE name.

20
Q

What does it mean to be a strongly typed language?

A

Static typing is where the type is bound to the variable. Types are checked at compile time.

Dynamic typing is where the type is bound to the value. Types are checked at run time.

A strongly-typed programming language is one in which each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data types.

21
Q

How can you test if an instance of an object implements a particular interface?

A

if(myObject is IMyInterface) { // object myObject implements IMyInterface }

22
Q

What is a static member or property in .Net?

A

Astaticclass is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use thenewoperator to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. For example, if you have a static class that is named UtilityClass that has a public static method named MethodA, you call the method as shown in the following example: UtilityClass.MethodA();

23
Q

What does your typical error handling code look like?

A

try
{
result = services.method(“datatobepassed.com”)

}

catch (Argument ex)
{
response = new ErrorResponse(ex.Message)
base.Logger.LogError(ex.ToString());
}
catch (Exception ex)
{
response = new ErrorResponse(ex.Message)

base.Logger.LogError(ex.ToString());

}

catch (SqlException/whatever specific ex)
{

response = new ErrorResponse($”Generic Error: ${sqlEx.Message}”)

base.Logger.LogError(sqlEx.ToString());

24
Q

What is the Web.Config/ApplicationSettings.json? What do you use it for?

A

The web.config/appsettings.json file is an application configuration file used to store configuration settings such as database connections strings, any application scope global variables, etc.

25
Q

What is Authorization? At what level does it typically happen your application?

A

Authorization refers tothe process that determines what a user is able to do. For example, an administrative user is allowed to create a document library, add documents, edit documents, and delete them. Happens closer to the controller.

26
Q

How does one implement this? (Make sure only known users are allowed to execute code)

A

Web API provides a built-in authorization filter, AuthorizeAttribute. This filter checks whether the user is authenticated. If not, it returns HTTP status code 401 (Unauthorized), without invoking the action. You can apply the filter globally, at the controller level, or at the level of individual actions. User[Authorize]above your code like http request or data validation

27
Q

How would you declare an array in C#

A

int[] array = new int[5]

string[] array = new string[]

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/single-dimensional-arrays

28
Q

What are Collections in .Net?

A

NET collection isa set of similar type of objects that are grouped together.

29
Q

What are Connection Strings?

A

A connection stringprovides the information that a provider needs to communicate with a particular database. The Connection String includes parameters such as the name of the driver, Server name and Database name , as well as security information such as user name and password.

30
Q

What are the different parts of a Connection String?

A

name of the driver, Server name and Database name , as well as security information such as user name and password.

31
Q

What are Nullable Types?

A

The Nullable typeallows you to assign a null value to a variable.

32
Q

How do you access the underlying value of a Nullable Type?

A

Nullable.Value

33
Q

In an API application, what information is used to route your request?

A

the http url data.

34
Q

What protocol is normally used in a web request?

A

Hypertext Transfer Protocolhttp

35
Q

What are the different types of HTTP methods? When would you use these over others?

A

GET - requests data

POST - SUBMIT to a specified resource

PUT - UPDATE data on a target resource

DELETE - DELETES specified resources

36
Q

What is attribute routing?

A

As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web API. For example, you can easily create URIs that describe hierarchies of resources.

[Route(“customers/{customerId}/orders”)]
public IEnumerable GetOrdersByCustomer(int customerId) { … }