.Net Flashcards

1
Q

If this class was going to participate in Model binding in the MVC request life cycle, is it currently set up to report as invalid when no data is sent to the server? (Assume FirstName & LastName are required.)

A

No. It is lacking data validation.

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

What would you have to do to make this model (Contact) report “Invalid” in such a case?

A

[Required] needs to be included before the variable is declared, along with any specific validation requirements such as string length or number range.

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

What namespace do these attributes live in?

A

Validation attributes live in the System.ComponentModel.DataAnnotation namespace.

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

Can you create an instance of an abstract class?

A

No, you cannot create an instance of an abstract class, but you can inherit it.

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

JavaScript is primarily used for front-end web development, while C# is commonly used for back-end development and desktop applications, though it’s also used in game development.

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

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

A

You can use the instanceof operator in JavaScript to test if an object implements a particular interface.

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

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

A

By using the .HasValue extension to check if the nullable has a value and by using .Value to actually access it.

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

How do you declare a variable in C#?

A

Data Type, Variable Name, Initial Value (optional)

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

How do you send email on the server?

A

Using the System.Net.Mail namespace in C# for ASP.NET applications.

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

How do you store Flags in an Enum?

A

By using the [Flags] attribute and assigning each enum member a value that is a power of 2, allowing bitwise operations to combine multiple flags.

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

What are the first 4 numeric values of an Enum used to store Flags?

A

The first 4 numeric values of an enum used to store flags are typically 0, 1, 2, and 4, with each value being a power of 2 to facilitate bitwise operations.

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

What is IEnumerable and what significance does it hold?

A

It is an interface that allows you to loop over an entire collection. They can be enumerated (iterated) one at a time. It is flexible when it comes to datatype and it does not need to be given conditions until actually needed.

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

How does the webserver know who you are across different web requests? Would this method work if you were to switch out browsers in the middle of a session?

A

The web server typically identifies users across different web requests through session management mechanisms like cookies or session IDs, which are stored either in the browser’s memory or as cookies. This method wouldn’t work if you switched out browsers in the middle of a session unless you manually transferred the session identifier between browsers.

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

How would you declare an array in C#?

A

By placing [] after the datatype that the array will be made of: int[] will indicate an array of integers

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

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

A

A class can inherit from only one base class directly, but it can implement multiple interfaces.

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

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

A

the HTTP method (GET, POST, PUT, DELETE), the request URL, and any additional parameters or headers provided in the request.

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

What are all the different types of validations that these attributes let you perform?

A

Required, StringLength, Range, EmailAddress, Phone Numbers, Compare, RegularExpression, DataType, Custom Validation

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

What are C# extension methods?

A

C# extension methods allow you to add new methods to existing types without modifying their source code, providing a way to extend functionality without inheritance or modifying the original type.

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

What are Connection Strings?

A

A connection string provides the information that a provider needs to communicate with a particular database.

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

What are the different parts of a Connection String?

A

name,provider name, ip address and password

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

What are Collections in .Net?

A

Collections are classes and interfaces that provide data structures for storing and manipulating groups of related objects.
(lists, dictionaries, queues, stacks, and sets)

22
Q

What are Generics in .Net?

A

Generics in .NET are a feature that allows classes, structures, interfaces, and methods to be parameterized by one or more types, enabling the creation of reusable and type-safe code. They provide flexibility and performance improvements by allowing algorithms and data structures to work with any data type while maintaining type safety at compile time.

23
Q

Why are Generics so important?

A

they enable the creation of highly reusable and type-safe code, reducing the need for code duplication and enhancing maintainability.

24
Q

What are Interfaces?

A

Interfaces in programming are blueprints for classes, defining a set of method and property signatures that implementing classes must adhere to. They provide a way to enforce contracts and achieve polymorphism, allowing different classes to be treated interchangeably based on shared behaviors defined by the interface.

25
Q

What are Nullable Types?

A

They are variables that are assigned to a datatype, but they are also assigned the ability to be null.

26
Q

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

A

SqlConnections – represents a connection to a database

SqlCommand – represents a SQL command to be executed against the database

SqlParameter – represents a parameter for a command.

DataSet and DataTable – represent in-memory caches or tables of data

SqlDataAdapter – works as a bridge between DataSet and a database
// Create a DataSet and fill it with data using SqlDataAdapter

SqlDataReader

27
Q

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

A

API controllers are focused on providing data to be consumed by clients (like web or mobile applications) so they use HTTP to retrieve the data, while regular/view controllers are focused on rendering HTML views for web browsers.

28
Q

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

A

POST to add, PUT to update/modify, DELETE to remove, GET to retrieve

29
Q

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

A

What are the datatypes accepted by the model and are they in the correct order necessary for communicating with the database?

30
Q

What are the principles of object-oriented programming? Provide examples of each.

A
  1. Encapsulation- Bundling data and the methods that operate on that data into a single unit
    -Service File contains functions and variables for carrying out the service requests.
  2. Polymorphism – Adapting code to a different type to be used in a different situation.
    -method overriding/overloading
  3. Inheritance – Reusing properties and behaviors from a parent class
    - An UpdateRequestModel inherits an AddRequestModel
  4. Abstraction – Hiding complex implementation details and exposing only the essential features of an object or system.
    - The Interface used with the API Controller only shares the public methods with the Service File.
31
Q

What do you use to debug C#?

A

Visual Studio’s debugger is and breakpoints.

32
Q

What does it mean to be a strongly typed language?

A

Variable types are enforced by the compiler, providing strict type checking and preventing implicit type conversions.

33
Q

What does your typical error handling code look like?

A

My typical error handling code involves using try-catch blocks to catch exceptions, logging the error details, and possibly providing feedback to the user or gracefully handling the error scenario.

34
Q

What is a Model?

A

A model is a representation of data and business logic in an application, often in the form of classes or structures that encapsulate data and behavior.

35
Q

What is a Null Reference Exception?

A

A Null Reference Exception prevents an application from running if a variable is null that is expected to have a value.

36
Q

What is a static member or property in .Net?

A

Static members/properties belong to the type itself rather than to the instances of that type, allowing access without requiring an instance to be created.

37
Q

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

A

An abstract class is a class that cannot be instantiated on its own and may contain both abstract and non-abstract members, while an interface is a contract that defines a set of method and property signatures that implementing classes must adhere to, but it cannot contain implementation code.

38
Q

What is an MVC View?

A

An MVC View is a presentation layer component responsible for rendering the user interface by displaying data from the model and handling user interactions.

39
Q

What is attribute routing?

A

Attribute routing allows you to define routes directly on the actions or controllers, providing a more intuitive way to associate URLs with specific code. [HttpPut(“{id:int}”)]

40
Q

What is Authorization? At what level does it typically happen in your application? How does one implement this? (Make sure only known users are allowed to execute code)

A

Authorization is process of confirming that a user has the proper permissions to access the information they are requested, typically occurring at the controller or action method level. However, in using the [Authorize] attribute in a controller, requests will only be carried out if the user has the correct authorization.

41
Q

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

A

It is the process of using model classes as bridges between front and back-end service requests to ensure the correct types and shapes of data are being transferred.

42
Q

What is the best way to concatenate strings in .Net and why?

A

For large concatenations that involve looping, StringBuilder is best because it avoids building unnecessary intermediate string objects.

43
Q

What is the difference between a string and a string builder and when would you use one over the other?

A

Use a string when the value is fixed and won’t change, and use a StringBuilder when you need to manipulate or concatenate strings frequently.

44
Q

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

A

ADO.net

45
Q

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

A

These are configuration files (web.config in .Net Framework and appsettings.json in .Net Core) that are required on start-up for an application to fire. They contain the required information such as connection strings and application scope variables.

46
Q

What protocol is normally used in a web request?

A

Hypertext Transfer Protocol (HTTP) –
it is the foundation of data communication on the web

47
Q

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

A

In MVC, we inherit from Controller. In API, we inherit from the ControllerBase.

48
Q

Write a C# function that accepts an array of integers, adds all the members, and returns the result.

A

public int sum(int[] arr){
int total = 0;
foreach (int num in array)
{
total += num;
}
return total;
}

49
Q

Write out an example class diagram (a diagram showing how several classes are related) for the objects described description.
a. Include Classes for:
i. Base person class
ii. Employee class
iii. Manager class
iv. Robot class
b. Include interfaces for:
i. “People”
ii. “Robots”
iii. An interface that both implement
c. Include an example of an abstract method and an abstract class
d. Be sure to have an example of how you leverage inheritance

A
50
Q

Write out the C# function that accepts two numbers - adds these numbers - returns the result of the addition:

A
51
Q

What is the difference between an Object and a Class?

A

A Class is a blueprint of information and when it is instantiated, an Object is created for actually working with the properties/features of the class. The Object is the tangible, real-life object to work with.