Code That Fits In Your Head Tips

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Query design per dataset mode

!Really understand this in chp 2!

In ASP.NET Core, what is a Startup class used for?

: In ASP.NET Core, a Startup class can be used to cleanly separate the addition and configuration of dependency services from the configuring of middleware in the request and response pipeline, like error handling, security options, static files, default files, endpoint routing, Razor Pages and MVC, and Entity Framework Core data contexts. The default project templates for ASP.NET Core 6 do not use a Startup class and instead put all the configuration code in Program.cs

What type would you use for the property that represents a table, for example, the Products property of a database context?

:DbSet, where T is the entity type, for example, Product.

In a shared layout file such as _Layout.cshtml, how do you output the content of the current view?

@RenderBody()

What are the two required parts of LINQ?

A LINQ provider and the LINQ extension methods. You must import the System.Linq namespace to make the LINQ extension methods available and reference a LINQ provider assembly for the type of data that you want to work with, except for the LINQ to Objects and LINQ to XML providers that are built-in to .NET

What do the files with the special names _ViewStart and _ViewImports do when created in the Views folder?

A _ViewStart file contains a block of statements that are executed when the View method is executed when a controller action method passes a model to a view, for example, to set a default layout. • A _ViewImports file contains @using statements to import namespaces for all views to avoid having to add the same import statements at the top of all views.

What are the signatures of the constructors that all exceptions should have?

A constructor with no parameters • A constructor with a string parameter, usually named message • A constructor with a string parameter, usually named message, and an Exception parameter, usually named innerException

What is a delegate?

A delegate is a type-safe method reference. It can be used to execute any method with a matching signature

What's the difference between a destructor and a deconstruct method?

A destructor, also known as a finalizer, must be used to release resources owned by the object. A deconstruct method is a feature of C# 7 or later that allows a complex object to be broken down into smaller parts. It is especially useful when working with tuples.

What is the difference between a field and a property?

A field is a data storage location that can be referenced. A property is one or a pair of methods that get and/or set a value. The value for a property is often stored in a private field.

What is the difference between a namespace and an assembly?

A namespace is the logical container of a type. An assembly is the physical container of a type. To use a type, the developer must reference its assembly. Optionally, the developer can import its namespace, or specify the namespace when specifying the type.

Transformation Priority Premise

A technique that talks about refactoring driven by testing these small changes. There is a list of them but the idea is that these small changes is what you should learn/focus on when making the changes.

What is a tuple?

A tuple is a data structure consisting of multiple parts. They are used when you want to store multiple values as a unit without defining a type for them.

What is the difference between a verbatim string and an interpolated string?

A verbatim string is prefixed with the @ symbol and each character (except ") is interpreted as itself; for example, a backslash \ is a backslash \. An interpolated string is prefixed with the $ symbol and can include expressions surrounded with braces like this: {expression}.

By convention, what suffix should be applied to a method that returns Task or Task?

Add the suffix Async to the method name, for example, for a synchronous method named Open, use OpenAsync for the equivalent that returns a Task or Task

Cyclomatic Complexity

Also known as Cyclomatic number. The number of independent paths through a program.

What is an event?

An event is a field that is a delegate having the event keyword applied. The keyword ensures that only += and -= are used; this safely combines multiple delegates without replacing any existing event handlers.

10. What is an extension method and how do you define one?

An extension method is a compiler trick that makes a static method of a static class appear to be one of the members of another type. You define which type you want to extend by prefixing the first parameter of that type in the method with the this keyword.

What is an object graph?

An object graph is any set of connected instances of classes that reference each other. For example, a Customer object may have a property named Orders that references a collection of Order instances.

What interface must an object implement to be enumerated over by using the foreach statement?

An object must "implement" the IEnumerable interface

2. What is the difference between the ReadByte method and the Read method of a stream?

Answer: The ReadByte method returns a single byte each time it is called, while the Read method fills a temporary array with bytes up to a specified length. It is generally best to use Read to process multiple bytes at once

List five LINQ extension methods that perform aggregation.

Any five of the following: Max, Min, Count, LongCount, Average, Sum, and Aggregate.

Postel's Law

Be liberal in what you accept, and conservative in what you send.

How do you create a child task?

Call the Task.Factory.StartNew method with the TaskCreationOptions. AttachToParent option to create a child task

Power BI deployment modes

Corporate BI : The Corporate BI delivery approach in which the BI team develops and maintains both the Power BI dataset (sometimes called a data model) and the required report visualizations is a common deployment option, particularly for large-scale projects and projects with executive-level sponsors or stakeholders. Self-Service Visualization In the Self-Service Visualization approach, the dataset is created and maintained by the IT organization's BI team, but certain business users with Power BI Pro licenses create reports and dashboards for consumption by other users Self-Service BI In the Self-Service BI approach, the BI organization only contributes essential infrastructure and monitoring, such as the use of an on-premises data gateway and possibly Power BI Premium capacity to support the solution.

How can you create your own LINQ extension methods?

Create a static class with a static method with an IEnumerable parameter prefixed with this

Dataset planning

Data transformations and Import, DirectQuery, Live, and Composite decision

Power BI project roles

Dataset Designers, The dataset designer is responsible for the data access layer of the Power BI dataset, including the authentication to data sources and the M queries used to define the tables of the data model. Additionally, the dataset designer defines the relationships of the model and any required rowlevel Report Authors,Report authors interface directly with the consumers of reports and dashboards or a representative of this group. and Power BI Admin(s)Power BI administrators are responsible for ensuring Power BI is utilized effectively and according to the organization's policies.

What benefits does endpoint routing provide?

Endpoint routing provides improved performance of routing and action method selection and a link generation service.

What is the difference between framework-dependent and self-contained deployments of modern .NET applications?

Framework-dependent modern .NET applications require .NET to be installed for an operating system to execute. Self-contained .NET applications include everything necessary to execute on their own.

List six method names that can be specified in an HTTP request

GET, HEAD, POST, PUT, PATCH, and DELETE. Others include TRACE, OPTIONS, and CONNECT

What does the acronym HSTS stand for, and what does it do?

HTTP Strict Transport Security (HSTS) is an opt-in security enhancement. If a website specifies it and a browser supports it, then it forces all communication over HTTPS and prevents the visitor from using untrusted or invalid certificates.

Why should you not wrap your use of HttpClient in a using statement to dispose of it when you are finished even though it implements the IDisposable interface, and what should you use instead?

HttpClient is shared, reentrant, and partially thread-safe, so it is tricky to use correctly in many scenarios. You should use HttpClientFactory, which was introduced in .NET Core 2.1

Why do you need to apply the [Flags] attribute to an enum type when you want to store combined values?

If you don't apply the [Flags] attribute to an enum type when you want to store combined values, then a stored enum value that is a combination will be returned by a call to ToString as the stored integer value instead of one or more of the commaseparated lists of text values

What is the benefit of using async and await in a website or web service?

In a website or web service, using async and await improves scalability but not the performance of a specific request because extra work in handling work between threads is required.

Base Class Library

Is a part of FCL which contains standard classes that can be used by any .NET languages.

What is the best serialization format to choose for minimizing space requirements?

JavaScript Object Notation (JSON) has a good balance between space requirements and practical factors such as human readability, but protocol buffers are best for minimizing space requirements

Data profiling

Learning more about the data in its entirety, like how many empty rows are in a column for a type

Common Language Runtime

Responsible for managing the execution of the Intermediate Language (IL) instructions

SQL views

SQL views are essentially virtual tables that provide an abstraction layer from the underlying database tables. SQL views can be used to merge database tables and to limit the number of columns, thus preventing such transformations from occurring within Power Query queries

Which LINQ extension method would you use to return a subset of properties from a type?

Select

What is the difference between the Select and SelectMany extension methods?

Select returns exactly what you specify to return. SelectMany checks that the items you have selected are themselves IEnumerable and then breaks them down into smaller parts. For example, if the type you select is a string value (which is IEnumerable), SelectMany will break each string value returned into their individual char values and combine them into a single sequence

Encapsulation

Sets up a contract, you follow it, it is expected to work

Power BI licenses

Shared capacity Two licensing options exist for using shared capacity within the Power BI service: • Free • Pro Dedicated capacity Three licensing options exist for using dedicated capacity within the Power BI service: • Premium • Premium Per User • Embedded

When would you use the StringReader, TextReader, and StreamReader classes

StringReader is used for efficiently reading from a string stored in memory. • TextReader is an abstract class that StringReader and StreamReader both inherit from for their shared functionality. • StreamReader is used for reading strings from a stream that can be any type of text file, including XML and JSON

+ Vertical Slice

Take the smallest feature and get it to a production state as quickly as possible. This proofs and sets up the rest of the project.

1. What is the difference between using the File class and the FileInfo class?

The File class has static methods, and it cannot be instantiated. It is best used for one-off tasks such as copying a file. The FileInfo class requires the instantiation of an object that represents a file. It is best used when you need to perform multiple operations on the same file

What is the difference between IEnumerable and IQueryable and how do you switch between them?

The IEnumerable interface indicates a LINQ provider that will execute the query locally, like LINQ to Objects. These providers have no limitations but can be less efficient The IQueryable interface indicates a LINQ provider that first builds an expression tree to represent the query and then converts it into another query syntax before executing it, like Entity Framework Core converts LINQ queries to SQL statements. These providers sometimes have limitations, such as a lack of support for certain expressions, and may throw exceptions. You can convert from an IQueryable provider to an IEnumerable provider by calling the AsEnumerable method

When should you use the SortedDictionary class rather than the SortedList class?

The SortedList class uses less memory than SortedDictionary; SortedDictionary has faster insertion and removal operations for unsorted data. If the list is populated all at once from sorted data, SortedList is faster than SortedDictionary

Which LINQ extension method would you use to filter a sequence?

The Where method allows filtering by supplying a delegate (or lambda expression) that returns a Boolean to indicate whether the value should be included in the results

What does the acronym CORS stand for, and why is it important to enable it in a web service?

The acronym CORS stands for Cross-Origin Resource Sharing. It is important to enable it for a web service because the default browser same-origin policy prevents code downloaded from one origin from accessing resources downloaded from a different origin to improve security

To use the await keyword inside a method, which keyword must be applied to the method declaration?

The async keyword must be applied to the method declaration

What is the benefit of a LINQ extension method that ends with OrDefault?

The benefit of a LINQ extension method that ends with OrDefault is that it returns the default value instead of throwing an exception if it cannot return a value. For example, calling the First method on a sequence of int values would throw an exception if the collection is empty but the FirstOrDefault method would return 0

What does the default model binder do, and what data types can it handle?

The default model binder sets parameters in the action method. It can handle the following data types: • Simple types like int, string, and DateTime, including nullable types. • Complex types like Person and Product. • Collection types like ICollection or IList

What is the difference between the is and as operators?

The is operator returns true if an object can be cast to the type; otherwise, it returns false. The as operator returns a reference to the object if an object can be cast to the type; otherwise, it returns null.

What does the last type parameter T in generic Func delegates like Func represent?

The last type parameter T in generic Func delegates like Func represents the type of the return value. For example, for Func, the delegate or lambda function used must return a Boolean value

Why should you avoid the lock keyword?

The lock keyword does not allow you to specify a timeout; this can cause deadlocks. Use the Monitor.Enter method and pass a TimeSpan argument as a timeout and then call the Monitor.Exit method explicitly to release the lock at the end of your work instead

What is the maximum number of characters that can be stored in a string variable?

The maximum size of a string variable is 2 GB, or about one billion characters, because each character uses 2 bytes due to the internal use of Unicode (UTF-16) encoding for characters in a string.

How many bytes per character does UTF-8 encoding use?

The number of bytes per character used by UTF-8 encoding depends on the character. Most Western alphabet characters are stored using one byte. Other characters may need two or more bytes.

What does the record keyword do?

The record keyword defines a data structure that is immutable by default to enable a more functional programming style. Like a class, a record can have properties and methods, but the values of properties can only be set during initialization

What does the underscore _ represent in a switch expression?

The underscore _ represents the default return value

Which class should you inherit from to create a controller class for an ASP.NET Core Web API service?

To create a controller class for an ASP.NET Core Web API service, you should inherit from ControllerBase. Do not inherit from Controller as you would in MVC because this class includes methods like View that use Razor files to render HTML not needed for a web service

How do you mix C# code into the middle of HTML to create a dynamic page?

To mix C# code into the middle of HTML to create a dynamic page, you can create a Razor file with the .cshtml file extension, and then prefix any C# expressions with the @ symbol, and for C# statements, wrap them in braces or create a @functions section, as shown in the following markup:

What must you do to specify which controller action method will be executed in response to an HTTP request?

To specify which controller action method will be executed in response to a request, you must decorate the action method with an attribute. For example, to respond to an HTTP POST request, decorate the action method with [HttpPost].

When should you use the Mutex class instead of the Monitor class

Use Mutex when you need to share a resource across process boundaries. Monitor only works on resources inside the current process.

Why is it bad to use a string value like "\Code\Chapter01" to represent a path and what should you do instead?

Use this...Path.Combine(new[] { "Code", "Chapter01" }); to not assume direction of backslash

What statement should you use to rethrow a caught exception named ex without losing the stack trace?

Use throw;. Do not use throw ex; because this will lose stack trace information

When is it appropriate to use a StringBuilder class?

When concatenating more than about three string variables, you will use less memory and get improved performance using StringBuilder than using the string. Concat method or the + operator.

Why is the partial keyword useful?

You can use the partial keyword to split the definition of a type over multiple files. Its not only classes, can be methods but must be in partial classes

Why should you be careful when using the dynamic type?

You should be careful when using the dynamic type because the type of object stored in it is not checked until runtime

When should you use the Interlocked class?

You should use the Interlocked class to modify integers and floating-point numbers that are shared between multiple threads

Project discovery and ingestion

a list of questions that describe the project's requirements and scope

What is a top-level program

a project that does not need to explicitly define a Program class with a Main method entry point

Which keyword is used to prevent a class from being instantiated with the new keyword?

abstract

Dataset design

four-step dataset design process: 1. Select the business process 2. Declare the grain 3. Identify the dimensions 4. Define the facts

Can you cancel a task? If so, how?

https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/cancel-an-async-task-or-a-list-of-tasks

Global Imports in C#10

imports some commonly used namespaces like System for use in all code files

Query folding

it translates M expressions into equivalent query statements for the given source system to process

What are the six combinations of access modifier keywords and what do they do?

private: This modifier makes a member only visible inside the class. • internal: This modifier makes a member only visible inside the same assembly. • protected: This modifier makes a member only visible inside the class or derived classes. • internal protected: This modifier makes a member only visible inside the class, derived classes, or within the same assembly. • private protected: This modifier makes a member only visible inside the class or derived classes that are within the same assembly. • public: This modifier makes a member visible everywhere

Strangler Pattern

refactor legacy code side by side, eg create new function then migrate all the callers to it

What are the differences between the static, const, and readonly keywords when applied to a type member?

static: This keyword makes the member shared by all instances, and it must be accessed through the type, not an instance of the type. • const: This keyword makes the field a fixed literal value that must never change because, during compilation, assemblies that use the field copy the literal value at the time of compilation. • readonly: This keyword restricts the field so that it can only be assigned to using a constructor or field initializer at runtime.

How can you determine how many bytes a type like double uses in memory?

using the sizeof() operator

Which keyword is used to allow a member to be overridden?

virtual

Triangulation

you add more and more tests and the code proves to be more generic

What are the names of the three segments defined in the default ASP.NET Core MVC route, what do they represent, and which are optional?

{controller}: For example, /shippers represents a controller class to instantiate, for example, ShippersController. It is optional because it can use the default value Home. • {action}: For example, /privacy represents an action method to execute, for example, Privacy. It is optional because it can use the default value Index. • {id}: For example, /5 represents a parameter in the action method, for example, int id. It is optional because it is suffixed with ?


Kaugnay na mga set ng pag-aaral

ARTH- 452E The Skyscraper Exam #3

View Set

ENTREPRENEURSHIP Chapters 10, 11, 12

View Set

Global Corporate Citizenship Exam #2

View Set

Pearson Microeconomics Hw Ch.4-6

View Set

Module 2: Leadership & Management; PART 2 (EXAM 1)

View Set