Close contact with C #4.0

Source: Internet
Author: User

It took two nights to finish reading New features in CSharp 4.0.docx. One of the biggest concerns is the great changes in the upstream of Dynamic Language Programming and COM's interoperability. The former will be C # With python and ruby language features, and the latter will better support office programming.

I don't know much about it in many places, so I need to study it further. I will update this article occasionally.

The first topic: the biggest change is that it has the characteristics of Dynamic Language.

Focuses on the following aspects:

Ø dynamic programming language object

Ø get COM object through IDispatch

Obtain the. Net type through reflection

Ø object structure changes, similar to html dom objects

C # better realize object interaction while retaining the static language.

The second topic is to maintain co-evolution with VB.

C #4.0New Features

Dynamic query

Named and optional parameters

COM-specific interoperability features

Flexibility

Dynamic query

Dynamic type

Dynamic Operators

Run-Time query

COM Object

Dynamic Object

Common Object

Excessive resolution of Dynamic Parameters

Dynamic Language Runtime

Current progress 6 pages

Existing Problems

You cannot use LINQ to query dynamic objects. Lambda cannot be passed as a parameter to a dynamic operation.

Specify parameters and any parameters

COMInteroperability features

Dynamic reference

NO PIASCompile

This function improves code compilation efficiency and reduces the memory occupied by assembly loading. For more information, see the new feature series of webcast <. NET 4.0 (1): Type Equivalency (>

Omitted ref

Inverter

Func <object, string> can be used as follows: Func <string, object>.

Limitations

IEnumerable <int> is not the same as IEnumerable <object>. Because the conversion from an integer to an object is a boxing operation, rather than a reference transformation.

Example at the end of document 3

Problems with the code I copied from the word file to VS2010 BETA2:

Var processes = Process. GetProcesses ()
. OrderByDescending (p & gt; p. WorkingSet)
. Take (10 );

Solution: less than "<"Replace with" & lt ", greater than"> "with" & gt ". That is,. OrderByDescending (p => p. WorkingSet)

3.1 create a console-type project.

Complete code:
1 using System;
2 using System. Diagnostics;
3 using System. Linq;
4 using Excel = Microsoft. Office. Interop. Excel;
5 using Word = Microsoft. Office. Interop. Word;
6 namespace ConsoleApplication1
7 {
8 class Program
9 {
10 static void Main (string [] args ){
11 var excel = new Excel. Application ();
12 excel. Visible = true;
13 excel. Workbooks. Add (); // optional arguments omitted
14 excel. Cells [1, 1]. Value = "Process Name"; // no casts; Value dynamically
15 excel. Cells [1, 2]. Value = "Memory Usage"; // accessed
16 var processes = Process. GetProcesses ()
17. OrderByDescending (p => p. WorkingSet)
18. Take (10 );
19 int I = 2;
20 foreach (var p in processes ){
21 excel. Cells [I, 1]. Value = p. ProcessName; // no casts

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.