Do you know ?. NET Framework 4.5 five great features

Source: Internet
Author: User

Introduction

It has been almost a year since the release of. NET 4.5. However, with the recent release of most Microsoft products. as shown in the NET developer discussion, developers only know one or two features. Other features only stay in MSDN and exist in the form of simple documents.

For example. NET developers. when there is something new in the NET Framework kernel, most of them will only talk about Asynchronization and waiting (at least people who talk to me only talk about these features ).

In addition, it is difficult to integrate all the new features. These features may not sound as interesting as the work you are currently developing.

So in this article, I would like to mention five of my favorite features in the. NET4.5 kernel. Of course, this may be what I like but not yours. But what I do is that when I select these features, I also think about the large. NET community, and I hope I can meet this expectation.

If you want to compress files from folders, you can call the CreateFromDirectory function as follows.

ZipFile.CreateFromDirectory(@"D:\data",@"D:\data.zip");

If you want to decompress the package, you can call the ExtractToDirectory function shown in the following code.

ZipFile.ExtractToDirectory(@"D:\data.zip", @"D:\data\unzip");
Feature 3: Regular Expression timeout (timeout)

Regular Expressions are always the first choice for verification. If you are a newbie to regular expressions, see regular expressions. I have explained how regular expressions are executed. However, the typical logic parsing of a regular expression exposes it to DOS attacks. Let's try to understand what I just said.

For example, consider the regular expression "^ (\ d +) $ ". This regular expression indicates that only numbers are allowed. You can also see the regular expression symbol graph, which shows how the regular expression evaluates. Now let's assume we want to verify "123456X ". This will have six paths, as shown in.

Feature 4: optimize the configuration file (improve Startup Performance)

We all know that. NET code is a semi-compiled format. At runtime, the JIT (Just-in-Time) compiler executes and converts this semi-compiled IL code to machine native code. One of the biggest complaints about JIT is that when the. NET application is first executed, it runs very slowly because JIT is busy converting IL code to machine code.

To reduce the startup time, There is content called "optimize configuration file" in. NET4.5. The configuration file is a simple file that records the list of methods required by the application during startup and running. So when the application starts, the background JIT executes and converts the IL code of these methods to machine/native language.

The background JIT compiles the startup Method on multiple processors to further reduce the startup time. Note that you need a multi-core processor to optimize the configuration file. If you do not have a multi-core processor, this setting will be ignored.

Important: ASP. NET 4.5 and Silverlight 5 Applications Support Profileoptimization by default. Therefore, the above Code does not need to be written in these technologies.

Feature 5: Garbage Collection (garbage collection in the background)

Garbage collection is a really heavy task in. NET applications. When it is an ASP. NET application, it becomes heavier. ASP. NET applications run on the server. Many clients send requests to the server to generate object loads, so that garbage collection does try to clear unwanted objects.

Other three features worth exploring

  Set the default application domain Culture

In the previous version of. NET, if I want to set a culture, I need to set it in each thread. The following sample program demonstrates the pain of setting a culture at the Thread level. This is a real pain when we have a large number of multi-threaded applications.

CultureInfo cul = new CultureInfo(strCulture);Thread.CurrentThread.CurrentCulture = cul;Thread.CurrentThread.CurrentUICulture = cul;

In 4.5, we can set a culture at the application domain level and all threads in this application domain will inherit this culture. The following is the sample code for DefaultThreadCurrentCulture.

CultureInfo culture = CultureInfo.CreateSpecificCulture("fr-FR");CultureInfo.DefaultThreadCurrentCulture = culture;

  The array size exceeds 2 GB.

I'm not sure in what scenarios we will need a 2 GB container. So I personally don't know where we will use this feature. If I used to need such a large container, I would break it down into small portions. But I'm sure there should be a good reason to enable this feature in the framework.

  The console supports Unicode encoding.

I leave this feature out of scope for discussion because very few people work in console programs. I have seen people use the console for academic purposes. All in all, we now have Unicode support for console applications.

  Reference

  • Http://msdn.microsoft.com/en-us/library/ms171868.aspx
  • Mr Sukesh marla highlights ASP. NET 4.5 new features

When you are free, please check out my website www.questpond.com for. NET4.5 Interview Questions and answers. I have made a lot of effort in this regard.

Source article: Shivprasad koirala Translation: bole online-EluQ

Link: http://www.cnblogs.com/oooweb/p/dot-net-framework-speciality.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.