.Net Flashcards
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.)
No. It is lacking data validation.
What would you have to do to make this model (Contact) report “Invalid” in such a case?
[Required] needs to be included before the variable is declared, along with any specific validation requirements such as string length or number range.
What namespace do these attributes live in?
Validation attributes live in the System.ComponentModel.DataAnnotation namespace.
Can you create an instance of an abstract class?
No, you cannot create an instance of an abstract class, but you can inherit it.
Describe the main differences or considerations between the JS and C#.
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 can you test if an instance of an object implements a particular interface?
You can use the instanceof operator in JavaScript to test if an object implements a particular interface.
How do you access the underlying value of a Nullable Type?
By using the .HasValue extension to check if the nullable has a value and by using .Value to actually access it.
How do you declare a variable in C#?
Data Type, Variable Name, Initial Value (optional)
How do you send email on the server?
Using the System.Net.Mail namespace in C# for ASP.NET applications.
How do you store Flags in an Enum?
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.
What are the first 4 numeric values of an Enum used to store Flags?
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.
What is IEnumerable and what significance does it hold?
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 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?
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 would you declare an array in C#?
By placing [] after the datatype that the array will be made of: int[] will indicate an array of integers
In .Net how many classes can one class inherit from?
A class can inherit from only one base class directly, but it can implement multiple interfaces.
In an API application, what information is used to route your request?
the HTTP method (GET, POST, PUT, DELETE), the request URL, and any additional parameters or headers provided in the request.
What are all the different types of validations that these attributes let you perform?
Required, StringLength, Range, EmailAddress, Phone Numbers, Compare, RegularExpression, DataType, Custom Validation
What are C# extension methods?
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.
What are Connection Strings?
A connection string provides the information that a provider needs to communicate with a particular database.
What are the different parts of a Connection String?
name,provider name, ip address and password