.NET Interview Prep

¡Supera tus tareas y exámenes ahora con Quizwiz!

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

- Model binding in ASP.NET is a feature that automatically maps data from HTTP requests to the model properties or parameters of an action method in an MVC or Web API application. It eliminates the need to manually extract data from the request object and populate the model, making the development process faster and more efficient. - With model binding, developers can easily bind request data to a strongly typed model class, validate the data, and pass it to the business logic layer for processing. It also supports model validation, which automatically validates data annotations and returns errors to the user if the data is invalid. - Model binding is important because it simplifies the development process, reduces the amount of code required to handle HTTP requests, and improves the overall maintainability and scalability of the application. By using model binding, developers can focus on writing business logic and creating a better user experience, rather than worrying about how to extract and validate data from HTTP requests.

What is a Null Reference Exception?

A Null Reference Exception is a runtime error that occurs when a program attempts to use a null reference, meaning that it tries to access an object that doesn't exist or has not been initialized. In C#, it's represented by the System.NullReferenceException class. This type of error can occur when a variable is declared but not assigned a value, or when a variable is assigned null and then used as if it has a value. It can also happen when trying to call a method or access a property on an object that is null. Null Reference Exceptions can be tricky to debug, but common strategies include checking for null values before attempting to use an object, using defensive programming techniques such as null checks and exception handling, and using a debugger to track down the source of the error.

What are the different parts of a Connection String?

A connection string in .NET typically consists of the following parts: Server name or IP address: The name or IP address of the server where the database resides. Database name: The name of the database that the application wants to connect to. Authentication type: The type of authentication that the application will use to connect to the database. This can be either Windows Authentication or SQL Server Authentication. Username and password: The credentials of the user that the application will use to authenticate with the database, if SQL Server Authentication is used. Provider: The provider that will be used to establish the connection. This can be either the OLE DB provider or the SQL Server .NET Data Provider. Additional options: Additional options that may be required to connect to the database, such as encryption settings or timeouts. The format and order of these parts may vary depending on the specific database and provider being used.

What are Connection Strings?

A connection string is a string that specifies information about a data source and the means of connecting to it, including the server name, database name, credentials, and other information needed to establish a connection. In .NET, connection strings are used to connect to various data sources, such as SQL Server, MySQL, Oracle, and others. They are typically defined in the application configuration file, such as the web.config file for web applications or the app.config file for desktop applications. Connection strings play a critical role in establishing a connection to a data source and performing data operations using .NET data providers.

What is attribute routing?

Attribute routing is a way to define the routes for an ASP.NET MVC or Web API application by decorating your controllers and action methods with attributes. With attribute routing, you can define the routes directly on the controller methods, instead of defining them in a separate routing table. This makes it easier to read and maintain your code, as the routes are defined in the same place as the code that handles the request. Attribute routing can also help to make your URLs more descriptive and SEO-friendly. (SEO stands for Search Engine Optimization)

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

Authorization is the process of determining whether a user or system is allowed to access a particular resource or perform a particular action. In web applications, authorization typically happens at the application level, where the application checks whether the user is authenticated and whether the user has the necessary permissions to access a particular resource or perform a particular action. There are different ways to implement authorization in web applications, such as role-based access control, attribute-based access control, and policy-based access control. These methods allow developers to define access rules and restrictions based on user roles, attributes, or policies.

What are C# extension methods? Duplicate

C# extension methods allow developers to add new methods to existing classes without having to derive a new class, modify the original class, or use any type of inheritance. These methods are defined in a static class and can be called as if they were methods of the original class, making them useful for adding functionality to third-party or system classes. Extension methods must be static, and the first parameter of the method must be the type that is being extended. The "this" keyword is used to specify the type being extended. (See Example)

What does your typical error-handling code look like?

Error-handling code can vary depending on the specific requirements and complexity of the application being developed. However, some general guidelines that can be followed are: Catch exceptions at the appropriate level: Catch exceptions at the appropriate level of abstraction, depending on the level at which you can handle them effectively. This means catching exceptions at a high-level layer of your code where you can log them, recover from them, or provide a fallback mechanism if necessary. Provide meaningful error messages: Error messages should be clear, concise, and actionable. They should provide enough information to diagnose the issue, but not be overly technical or verbose. Log errors: Log all errors to an appropriate location, such as a file or a logging framework, along with contextual information like the error message, stack trace, and relevant data. This helps in troubleshooting issues that occur in production. Use try-catch blocks: Use try-catch blocks to handle exceptions that can be expected. This allows the application to recover gracefully from an error and prevents it from crashing.

Why are Generics so important?

Generics are important because they allow developers to create flexible, reusable code that can work with a variety of data types without having to rewrite the same code for each type. By using generics, developers can create data structures and algorithms that can operate on any type of data, making their code more efficient and easier to maintain. Generics also improve type safety by enabling the compiler to catch errors at compile time rather than at runtime, which can help prevent bugs and improve overall program stability. Additionally, generics can improve performance by reducing the need for boxing and unboxing operations that can slow down code execution.

What are Generics in .Net?

Generics in .NET are a feature that allow for the creation of classes, interfaces, and methods that can work with any data type. This means that code can be written once, but can work with different types of data without needing to be rewritten for each data type.

in .Net What is IEnumerable and what significance does it hold?

IEnumerable is an interface in .NET that is used to iterate over a collection of items. It defines a method GetEnumerator() which returns an IEnumerator object, which is used to iterate over the collection. IEnumerable is significant because it is the basis for LINQ (Language-Integrated Query), which is a set of language and framework features in .NET that provides a consistent way to query data from different sources. By implementing the IEnumerable interface, a collection can be queried using LINQ operators, such as Where(), Select(), and OrderBy(). In addition, many of the built-in collection classes in .NET implement the IEnumerable interface, which allows them to be used with LINQ and other APIs that depend on the interface.

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

In .NET, ADO.NET is the primary library used to communicate with databases. The key objects and classes used in ADO.NET for this purpose include: Connection: A connection object represents a connection to a database and provides methods for connecting to and disconnecting from the database. Command: A command object represents a SQL statement or stored procedure that is executed against a database. It provides methods for executing the command and returning results. DataReader: A data reader object provides forward-only, read-only access to data returned from a command. It is useful for handling large amounts of data or when performance is critical. DataSet: A dataset object is an in-memory representation of a set of data retrieved from a database. It can contain multiple tables, relationships, and constraints. DataAdapter: A data adapter object is used to populate a dataset with data from a database and to update changes made to the dataset back to the database. It provides methods for filling and updating datasets.

What are Collections in .Net?

In .NET, a collection is a group of related objects stored together as a single unit. It is a fundamental concept in .NET programming, as it allows developers to store and manipulate data in a structured way. The .NET framework provides several built-in collection classes, such as ArrayList, List, Dictionary, Queue, and Stack. These classes provide different ways to store and manipulate data, and each has its own strengths and weaknesses depending on the scenario.

What are Nullable Types?

In .NET, a nullable type is a value type that can also represent null. Value types, such as integers and booleans, cannot normally be assigned a null value because they are not reference types. However, nullable types allow you to assign a null value to a value type variable, which can be useful in certain situations. To create a nullable type in C#, you can use the question mark (?) notation after the value type. For example, int? is a nullable integer type that can hold an integer value or a null value. Nullable types can be particularly useful in database programming, where null values are often encountered in query results. They can also be used in other scenarios where you need to represent the absence of a value.

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

In .NET, a regular or view controller is responsible for handling user requests and returning the appropriate view to be rendered in the user's browser. On the other hand, an API controller is specifically designed for handling requests and returning data in a structured format such as JSON or XML.

What is a static member or property in .Net?

In .NET, a static member or property is a member that belongs to a type, rather than to an instance of that type. This means that a static member is shared across all instances of a class and can be accessed without creating an instance of the class. Static members and properties are marked with the static keyword in C#. Examples of static members include static fields, static properties, and static methods. They are commonly used to define constants, utility methods, or other data that should be shared across all instances of a class. Accessing a static member or property is done using the class name, followed by the member or property name, like this: "ClassName.StaticMemberName"

in .Net How does the webserver know who you are across different web requests?

In .NET, the web server typically uses a session management system to keep track of a user's identity across different web requests. When a user logs in to a web application, the server generates a unique session ID and stores it in a cookie or in the URL of subsequent requests. The session ID is then used to retrieve the user's session data, which can include information such as their identity, preferences, and any other relevant data. The session data is typically stored on the server side, in memory, a database, or a distributed caching system, depending on the configuration of the application. When the user makes a subsequent request, the server uses the session ID to retrieve the session data and continue the user's session. The session management system is a crucial component of web application security, as it allows the server to verify the identity of the user across multiple requests and enforce access control rules. It is also important for maintaining a seamless user experience, as it allows the server to remember the user's preferences and provide personalized content.

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

In .Net, the best way to concatenate strings is by using the StringBuilder class. This class provides efficient and optimized ways to concatenate strings by minimizing memory allocations and string copying. The reason StringBuilder is preferred over other methods like string.Concat() or + operator is that strings are immutable in .Net, which means every time you concatenate two strings, a new string is created in memory. This can cause performance issues if you are concatenating a large number of strings or doing it frequently. On the other hand, StringBuilder creates a mutable buffer and provides a Append() method to add strings to it. This buffer can be modified without creating new strings every time, resulting in faster and more efficient string concatenation. Finally, the ToString() method can be used to retrieve the concatenated string from the buffer. StringBuilder sb = new StringBuilder(); sb.Append("Hello"); sb.Append(" "); sb.Append("World"); string result = sb.ToString();

What is a Model? (Model View Controller)

In ASP.NET MVC, a Model typically corresponds to a database table, and it is responsible for retrieving, storing, and updating data in the database. The Model is often used by the Controller to retrieve data from the database and to pass that data to the View for display.

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

In C#, a class can only directly inherit from one base class. This is known as single inheritance. However, a class can implement multiple interfaces, which can provide similar functionality to multiple inheritance. Additionally, inheritance hierarchies can be created by having derived classes inherit from other derived classes, resulting in a chain of inheritance.

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

In C#, a string is an immutable object, which means that once a string object is created, it cannot be changed. On the other hand, a StringBuilder is a mutable object that can be modified without creating a new object every time a change is made. In general, if you have a small number of string manipulations, it is fine to use a regular string. However, if you have a large number of string manipulations, it is recommended to use a StringBuilder to avoid performance issues.

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

In C#, an abstract class is a class that cannot be instantiated on its own and is often used as a base class for other classes. It may contain both abstract and non-abstract members, including methods, properties, and fields. Abstract members have no implementation in the abstract class and must be implemented in derived classes. An interface, on the other hand, is a contract between a class and the outside world that defines a set of methods and properties that the class must implement. An interface contains no implementation of its own and only defines the structure of the members that must be implemented by the implementing class. So, while both abstract classes and interfaces define a contract that derived classes must implement, an abstract class can provide both abstract and non-abstract members, while an interface only provides a set of method and property signatures that must be implemented.

What are Interfaces?

In C#, an interface defines a contract or Agreement that specifies the properties, methods, and events that a class must implement. It defines a set of rules that any implementing class must adhere to. An interface defines only the signatures of the members without providing any implementation. The implementation of these members is left to the class that implements the interface. Interfaces are used extensively in C# to define contracts between different parts of the code, such as between classes and between layers in a multi-tier application. They provide a way to achieve loose coupling between the different parts of the code, enabling more flexibility and maintainability. Classes can implement multiple interfaces, allowing them to provide different behaviors for different contexts. They can also inherit from a base class while implementing one or more interfaces, allowing them to combine the behaviors of the base class and the interfaces.

How do you store Flags in an Enum?

In C#, you can define an enum with the [Flags] attribute to indicate that it represents a set of bit flags. To store flags in an enum, you need to assign each member of the enum a value that is a power of 2, starting from 1, and then combine them using the bitwise OR operator (|). Here's an example: csharp [Flags] enum Permissions { None = 0, Read = 1, Write = 2, Execute = 4 } In this example, each member of the Permissions enum has a value that is a power of 2. The None member has a value of 0, which represents the absence of any flags. The Read member has a value of 1, which represents the first flag. The Write member has a value of 2, which represents the second flag. The Execute member has a value of 4, which represents the third flag.

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

In C#, you can use the is keyword to test if an instance of an object implements a particular interface. The is keyword is used to check whether an object is compatible with a given type or not. SEE EXAMPLE: myObject is an instance of some class that may or may not implement the IMyInterface interface. The is keyword is used to test if myObject is compatible with the IMyInterface interface. If it is, the code within the if block will execute, otherwise, the code within the else block will execute.

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

In an API application, the request is typically routed based on the HTTP verb used in the request (e.g., GET, POST, PUT, DELETE) and the URL path. The URL path may contain route parameters that are used to extract data from the URL and pass it to the appropriate controller action method. Additionally, query string parameters and headers may also be used to route the request. Ultimately, the routing mechanism determines which controller action method should handle the request based on the available route information.

How do you send email on the server?

In order to send an email from a server in C#, you can use the System.Net.Mail namespace, which provides the SmtpClient and MailMessage classes. Here's an example code snippet that sends an email: java using System.Net.Mail; // Create a MailMessage object MailMessage message = new MailMessage(); message.From = new MailAddress("[email protected]"); message.To.Add(new MailAddress("[email protected]")); message.Subject = "Test Email"; message.Body = "This is a test email."; // Create a SmtpClient object and send the message SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587); smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "password"); smtpClient.EnableSsl = true; smtpClient.Send(message); Note that you will need to replace the SMTP server address, email addresses, and credentials with your own information. Also, you should handle any exceptions that may occur during the email sending process.

What does it mean to be a strongly typed language?

In programming, a strongly typed language is a language in which variables must be declared with a specific data type, and this data type cannot be changed without an explicit conversion. In other words, the data type of a variable is enforced by the language at compile-time, and any attempt to use a variable outside of its declared type will result in a compile-time error. C# is an example of a strongly typed language, and this strong typing allows for greater type safety, increased reliability, and improved maintainability of code. Strong typing also helps catch errors earlier in the development process, making it easier to debug and maintain code over time.

What is an MVC View?

In the context of ASP.NET, an MVC (Model-View-Controller) View is a user interface component that presents data from the application's model to the user. It is responsible for defining the structure and layout of the content that is displayed to the user. In an MVC architecture, the View is the component that interacts directly with the user, receiving input and rendering output based on the application's state. A View can be implemented using a variety of technologies, including HTML, CSS, and JavaScript, as well as server-side scripting languages like C#. It typically works in conjunction with a Controller, which is responsible for processing user input and updating the application's model accordingly. The View and Controller work together to provide a seamless user experience, with the View handling the presentation of data and the Controller managing the application's logic and state.

What do you use to debug C#?

Integrated Development Environment (IDE): Visual Studio is the primary IDE used to develop C# applications. It has a built-in debugger that allows developers to debug C# code. The debugger allows the developer to step through the code line by line, set breakpoints, and examine variables. Console.WriteLine(): This is a simple method that prints a message to the console. Developers can use this method to output messages and examine variable values during runtime. Debug.WriteLine(): This is similar to Console.WriteLine(), but it is part of the Debug class. It is useful when debugging complex applications. Debugger.Break(): This method allows developers to manually pause the execution of a program at a particular point. When the program hits this line of code, it will trigger a breakpoint, and the debugger will launch. Exception handling: Exception handling is a technique used to catch and handle errors that occur during runtime. Developers can use try-catch blocks to isolate problematic code and examine the error message. Third-party tools: There are several third-party tools available that can be used to debug C# code. Examples include JetBrains' dotTrace and Telerik's JustTrace. These tools offer more advanced features than the built-in Visual Studio debugger.

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

Model class: The model class should be created with all the required properties. The property names in the model class should match with the input field names in the view. The model class can also have data annotations to validate the data being entered. View: The view should be created with the same property names as that of the model class. Each input field in the view should have a name attribute, which matches with the property names in the model class. Controller: In the controller, the action method should be created with an HTTP POST attribute. The parameter for the action method should be the model class. When the form is submitted, the data is posted to the action method, and the model binding occurs. Data Annotations: Data annotations can be used in the model class to specify validation rules for the properties. This ensures that the data entered by the user is valid and helps in preventing any errors. ModelState: ModelState is an object that is used to check if the model is valid or not. If the model is not valid, then the ModelState object contains information about the error. The developer should check if the model is valid or not and perform any necessary actions based on the result. By considering these fundamentals, a developer can ensure that the model binding is wired up correctly and the data entered by the user is validated and saved in the database.

Can you create an instance of an abstract class?

No, you cannot create an instance of an abstract class directly.

What are the principles of object-oriented programming?

Object-oriented programming (OOP) is a programming paradigm that uses objects to represent and manipulate data. The principles of OOP are as follows: Encapsulation: The idea of encapsulation is to hide the internal workings of an object from the outside world, and to expose only the public interface of the object. This means that the object's data and methods are wrapped up into a single entity, which can be used without knowing how it works internally. Inheritance: Inheritance allows objects to inherit properties and methods from other objects. This means that objects can be created based on other objects, and can extend or modify their behavior. Polymorphism: Polymorphism means that objects of different types can be treated as if they are the same type. This allows for code reuse and more flexible programming. Abstraction: Abstraction means that objects are simplified versions of more complex things, and that only the relevant details are included. This makes objects easier to work with and understand. Modularity: Modularity means that objects are broken down into smaller, more manageable pieces. This makes the code easier to understand, maintain, and modify. By following these principles, OOP allows developers to create more flexible, modular, and scalable software.

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

The generic name of the library used in .Net to communicate with databases is ADO.NET.

Given the following input and .Net Class - is it currently set up to report as invalid when no data is sent to the Server? (Assume FirstName & Last Name are required) input: Bob Smith is 30 years old Has two direct reports. They are: - Sally Smith, 30 y/o - Jane Doe 34 y/o Model class: public class Contact { public string FirstName {get; set;} public string LastName {get; set;} public int Age {get; set;} public Contact[] Reports {get; set;} }

The model class does not currently have any validation attributes that enforce required fields, so it is not currently set up to report as invalid when no data is sent to the server. To enforce required fields, you could add validation attributes to the FirstName and LastName properties, such as [Required], and then check the ModelState.IsValid property in the controller to determine if the input is valid or not.

What protocol is normally used in a web request?

The protocol normally used in a web request is HTTP (Hypertext Transfer Protocol).

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

There are several HTTP methods, also known as HTTP verbs, that can be used in a web request: GET: used to retrieve information from a server. This method should be used when requesting data that is read-only and doesn't modify the server's state. POST: used to submit data to the server to create or update a resource. This method should be used when sending data to the server that will change its state. PUT: used to update a resource on the server. This method should be used when updating a resource that already exists. DELETE: used to delete a resource on the server. HEAD: similar to GET, but only returns the headers of a response, not the body. OPTIONS: used to retrieve the communication options available for a resource. PATCH: used to partially update a resource on the server.

What namespace do these attributes live in? - Required - Ensures that a property has a value. - StringLength - Validates the length of a string property. - Range - Validates a numeric property's range of values. - RegularExpression - Validates a string property against a regular expression pattern. - Compare - Validates two properties to ensure that their values are equal or not. - Custom - Allows you to write your own validation logic by creating a custom validation attribute.

These attributes live in the System.ComponentModel.DataAnnotations namespace in .NET.

How would you declare an array in C#

To declare an array in C#, you use square brackets [] after the data type and then provide the name for the array. Here's an example of how to declare an array of integers: int[] numbers; You can also initialize an array with values by using curly braces {} and separating each value with a comma. Here's an example: int[] numbers = { 1, 2, 3, 4, 5 }; You can also specify the size of the array when you declare it, like this: int[] numbers = new int[5]; This creates an array of integers with a length of 5, but all of the elements in the array are initialized to their default values (which is 0 for an array of integers)

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

To implement this in a .NET application, you can use the built-in authentication and authorization features provided by the framework. Here are the general steps to follow: Configure authentication: You need to configure the authentication mechanism for your application, such as Forms Authentication or Windows Authentication. This will allow your application to verify the identity of users who access your resources. Implement authorization: You can implement authorization by specifying the roles or users that are allowed to access specific resources in your application. You can use the [Authorize] attribute to restrict access to specific controllers or actions in your application based on the user's identity. Use role-based authorization: You can use role-based authorization to restrict access to specific resources in your application based on the user's role. To do this, you need to define roles for your application, and then assign users to those roles. Use Claims-based authorization: You can use Claims-based authorization to restrict access to specific resources in your application based on the claims associated with the user's identity. A claim is a piece of information about the user, such as their name or email address, that is stored as part of their identity. Use custom authorization: If the built-in authorization mechanisms do not meet your needs, you can implement custom authorization logic. This allows you to implement more complex authorization rules that take into account multiple factors, such as user roles, claims, and external data sources. Authorization typically happens at the controller level in your application, where you can restrict access to specific actions based on the user's identity, roles, or claims.

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

Types: C# is a statically typed language, meaning that variables must be explicitly declared with a specific type. JavaScript, on the other hand, is dynamically typed, which means that variables can be assigned a value of any type at runtime. Execution Environment: C# is typically used for building desktop applications, web applications, and games that run on Windows operating system, whereas JavaScript is primarily used for web development and runs in web browsers. Syntax: The syntax of C# is similar to other C-like languages, such as Java and C++, with semicolons, curly braces, and object-oriented programming concepts. JavaScript has a unique syntax that can be challenging to learn for those who are not familiar with it. Memory Management: C# is a managed language, which means that it provides automatic memory management through garbage collection. JavaScript, on the other hand, does not have automatic memory management and requires developers to manually manage memory. Asynchronous Programming: Asynchronous programming is an important aspect of modern web development, and both C# and JavaScript support it. However, C# has more powerful tools for asynchronous programming, such as the async/await keywords, whereas JavaScript relies on callback functions, Promises, and async/await for asynchronous programming. Frameworks and Libraries: C# has a robust ecosystem of frameworks and libraries for various purposes, such as .NET Framework, .NET Core, and Unity. JavaScript also has a vast array of frameworks and libraries, such as React, Angular, and Vue, that are widely used in web development.

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

When creating a new controller, you typically inherit from the System.Web.Mvc.Controller class. However, if you are working with ASP.NET Core, you would inherit from the Microsoft.AspNetCore.Mvc.ControllerBase class. When creating a new controller in .NET, you typically inherit from the Controller class (System.Web.Mvc.Controller ). However, in newer versions of .NET, such as .NET Core, you can inherit from different classes based on the type of controller you want to create (ex: Microsoft.AspNetCore.Mvc.ControllerBase) For example, if you're building an API controller, you would typically inherit from the ControllerBase class instead of the Controller class. This is because API controllers are typically used to implement RESTful APIs, which return data in a format such as JSON or XML, rather than rendering views. Overall, the specific class you inherit from when creating a new controller will depend on the requirements of your application and the version of .NET you are using. It's important to understand the differences between the different types of controllers and choose the appropriate base class for your needs.

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

You can access the underlying value of a nullable type using the .Value property, but only if the nullable type has a value. If the nullable type is null, accessing the .Value property will throw a InvalidOperationException. To safely access the underlying value of a nullable type, you can use the null-coalescing operator ??. See diagram In this example, the ?? operator returns the left-hand operand if it has a value, otherwise it returns the right-hand operand. In the first case, nullableInt is null, so the right-hand operand 0 is returned. In the second case, nullableInt has a value of 42, so that value is returned. also int? nullableInt = 10; if (nullableInt.HasValue) { int intValue = nullableInt.Value; Console.WriteLine("The value of the nullable int is: " + intValue); } else { Console.WriteLine("The nullable int has no value."); }

What are all the different types of validations Data Annotation attributes let you perform? (namespace: System.ComponentModel.DataAnnotations)

[Required] - Ensures that a property has a value. [StringLength] - Validates the length of a string property. [Range] - Validates a numeric property's range of values. [RegularExpression] - Validates a string property against a regular expression pattern. [Compare] - Validates two properties to ensure that their values are equal or not. [Custom] - Allows you to write your own validation logic by creating a custom validation attribute. [EmailAddress]: Specifies that a string property must be a valid email address. [Phone]: Specifies that a string property must be a valid phone number. [Url]: Specifies that a string property must be a valid URL. [CreditCard]: Specifies that a string property must be a valid credit card number.

What would you have to do to make this model (Contact) report "Invalid" in such a case? input: Bob Smith is 30 years old Has two direct reports. They are: - Sally Smith, 30 y/o - Jane Doe 34 y/o Model class: public class Contact { [Required] public string FirstName {get; set;} [Required] public string LastName {get; set;} public int Age {get; set;} public Contact[] Reports {get; set;} }

if the FirstName or LastName properties are not provided in the input, the ModelState.IsValid property will be false, indicating that the input is invalid.

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

public int AddNumbers(int num1, int num2) { int result = num1 + num2; return result; } call it like this: int sum = AddNumbers(5, 10); Console.WriteLine(sum); // output: 15

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

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

Would the method of sessionId tracking work if you were to switch out browsers in the middle of a session? (Where is the sessionId Stored)

Yes, the method should work even if you switch browsers in the middle of a session. The server tracks the user's session using a session ID that is stored on the server-side. As long as the user can provide the correct session ID, the server will recognize them as the same user, regardless of the browser they are using. Therefore, switching browsers in the middle of a session should not affect the server's ability to recognize the user.


Conjuntos de estudio relacionados

Iowa Property and casualty exam practice (CASUALTY)

View Set

SOWK6540: Intro to Research Study Guide

View Set

US History Chapters 17-20 Review

View Set

Core Subjects EC-6 practice test with Rationale

View Set

CompTIA Linux+ 3.8 Mounting and Unmounting Filesystems

View Set

Employment Law - Midterm - Manetta

View Set

ENG 270B Quotes for Final BOOK E

View Set

Nutrition 2 Vitamins and Minerals

View Set