.NET Framework 4.6 and 4.5 – walk-through – (Part 1)

 

.NET 2015 includes ASP.NET 5, which is a lean .NET platform for building modern cloud-based apps.

The platform is modular so you can include only those features that are needed in your application.

It can be hosted on IIS or self-hosted in a custom process, and you can run apps with different versions of the .NET Framework on the same server.

It includes a new environment configuration system that is designed for cloud deployment.

 

To build an app that uses MVC 6 or SignalR 3, you must use the project system in Visual Studio 2015.

You must be running on Windows 10 to use HTTP/2 with ASP.NET.

Code that targets the runtime is known as managed code, while
code that does not target the runtime is known as unmanaged code.

The following illustration shows the relationship of the common language runtime and the class library to your applications and to the overall system. The illustration also shows how managed code operates within a larger architecture.

 

Culture Info

 

IFormatProvider, ICustomFormatter

TelephoneFormatter example

 

The HttpRequest.UserLanguages property is populated from the culture names that are contained in Accept-Language headers included in an HTTP request.

However, not all browsers include Accept-Language headers in their requests, and users can also suppress the headers completely. This makes it important to have a fallback culture when parsing user input.

Typically, the fallback culture is the invariant culture returned by CultureInfo.InvariantCulture

 

Use the String.ToUpperInvariant method instead of the String.ToLowerInvariant method when you normalize strings for comparison

Use the String.Compare and String.CompareTo methods to sort strings, not to check for equality

Both StringComparison.Ordinal and StringComparison.OrdinalIgnoreCase use the binary values directly, and are best suited for matching. When you are not sure about your comparison settings, use one of these two values

The String object is immutable. Every time you use one of the methods in the System.String class, you create a new string object in memory, which requires a new allocation of space for that new object

StringBuilder Setting the Length property to a value that is less than the length of the string within the current StringBuilder shortens the string.

The backslash character (\) in a regular expression indicates that the character that follows it either is a special character or should be interpreted literally.

Regex

 

Lazy Regex example

Greedy and Lazy Quantifiers
A non-greedy quantifier tries to match an element as few times as possible. You can turn a greedy quantifier into a lazy quantifier by simply adding a ?.

Often, the single greatest factor that affects regular expression performance is the way in which the Regex engine is used

Interpreted vs. Compiled Regular Expressions
(No worries, answer below belongs to me 🙂

 

 

The Regex class itself is thread safe and immutable (read-only).

That is, Regex objects can be created on any thread and shared between threads; matching methods can be called from any thread and never alter any global state

 

Regular Expression Example: Scanning for HREFs

A character encoding has two distinct components:

An encoder, which translates a sequence of characters into a sequence of numeric values (bytes).

A decoder, which translates a sequence of bytes into a sequence of characters.

All character encoding classes in the .NET Framework inherit from the System.Text.Encoding class, which is an abstract class that defines the functionality common to all character encodings.

UTF-16 encoding is used by the common language runtime to represent Char and String values, and it is used by the Windows operating system to represent WCHAR values.

Consequently, you should use UTF-8 instead of UTF-7 if possible.

ASCII: in most cases it is inadequate for internationalized applications

If you have the opportunity to choose the encoding to be used by your application, you should use a Unicode encoding, preferably either UTF8Encoding or UnicodeEncoding

 

EncoderFallbackException example:

Generic collections were added in the .NET Framework 2.0 and provide collections that are type-safe at compile time. Because of this, generic collections typically offer better performance.

Starting with the .NET Framework 4, the collections in the System.Collections.Concurrent namespace provide efficient thread-safe operations for accessing collection items from multiple threads. The immutable collection classes in the System.Collections.Immutable namespace (NuGet package) are inherently thread-safe because operations are performed on a copy of the original collection and the original collection cannot be modified

Leave a Reply

Your email address will not be published. Required fields are marked *