Поделиться через


What's New in Visual C# 2010

This page lists the new and enhanced features available in Visual C# 2010. The new features work together to improve Microsoft Office programmability, increase your ability to explore code, provide support for test-driven development, and more. For more information, see Visual Studio 2010 Product Highlights.

Click the links in the following sections to read more about a feature.

C# 4.0 Language and Compiler

Dynamic Support

Visual C# 2010 provides support for late binding to dynamic types by introducing a new type, dynamic. This addition enables many new scenarios, including simplified access to COM APIs such as the Office Automation APIs, to dynamic APIs such as IronPython libraries, and to the HTML Document Object Model (DOM). For more information, see Using Type dynamic (C# Programming Guide) and dynamic (C# Reference).

Office Programmability

Access to COM interfaces, including the Office Automation APIs, is greatly enhanced by the addition of named and optional arguments, the dynamic type, indexed properties, and optional ref modifiers.

For more information, see Named and Optional Arguments (C# Programming Guide), Using Type dynamic (C# Programming Guide), How to: Use Indexed Properties in COM Interop Programming (C# Programming Guide), and How to: Access Office Interop Objects by Using Visual C# 2010 Features (C# Programming Guide).

Type Equivalence Support

You can now deploy an application that has embedded type information instead of type information that is imported from a Primary Interop Assembly (PIA). With embedded type information, your application can use types from an assembly without requiring a reference to the runtime assembly or Primary Interop Assembly (PIA). If various versions of the runtime assembly are published, the application that contains the embedded type information can work with the different versions without having to be recompiled. For more information, see /link (C# Compiler Options). For an example, see Walkthrough: Embedding Types from Managed Assemblies (C# and Visual Basic).

Covariance and Contravariance

Covariance enables you to use a more derived type than that specified by the generic parameter, whereas contravariance enables you to use a less derived type. This allows for implicit conversion of classes that implement variant interfaces and provides more flexibility for matching method signatures with variant delegate types. Variant interfaces and delegates can be created by using the new in and out language keywords. The .NET Framework also introduces variance support for several existing generic interfaces and delegates, including the IEnumerable<T> interface and the Func<TResult> and Action<T> delegates. For more information, see Covariance and Contravariance (C# and Visual Basic).

New Command-Line Options

The /langversion command-line option causes the compiler to accept only syntax that is valid in the specified version of C#.

The /appconfig compiler option enables a C# application to specify the location of an assembly's application configuration file to the compiler.

Visual C# Integrated Development Environment

The following sections describe enhancements to the Visual Studio integrated development environment (IDE).

Call Hierarchy

Call Hierarchy enables you to navigate through your code by displaying the following:

  • All calls to and from a selected method, property, or constructor

  • All implementations of an interface member

  • All overrides of a virtual or abstract member

This enables you to better understand how code flows and to evaluate the effects of changes to code. For more information, see Call Hierarchy.

You can use the Navigate To feature to search for a symbol or file in source code. You can search for keywords that are contained in a symbol by using Camel Casing and underscore characters to divide the symbol into keywords.

For more information, see How to: Search for Objects, Definitions, and References (Symbols).

Highlighting References

When you click a symbol in source code, all instances of that symbol are highlighted in the document. To move to the next or previous highlighted symbol, you can use CTRL+SHIFT+DOWN ARROW or CTRL+SHIFT+UP ARROW. For more information, see How to: Use Reference Highlighting.

Generate From Usage

The Generate From Usage feature enables you to use classes and members before you define them. Without leaving your current location in code, you can generate a stub for a class, constructor, method, property, field, or enum that you want to use but have not yet defined. This minimizes interruption to your workflow.

Generate From Usage supports programming styles such as test-first development. For more information, see Generate From Usage and Walkthrough: Test-First Support with the Generate From Usage Feature.

IntelliSense Suggestion Mode

IntelliSense now provides two alternatives for IntelliSense statement completion: completion mode and suggestion mode. Suggestion mode is used when classes and members are used before they are defined. For more information, see List Members.

Live Semantic Errors

The Live Semantic Errors feature has been enhanced in Visual C# 2010. The use of wavy underlines to signal errors and warnings as you type has been extended to include constructs that are outside of method bodies, such as return types, parameter types, and default values in method declarations.

Sample Applications

Visual C# 2010 includes sample applications that demonstrate the use of new C# features to simplify Office programming, provide access to IronPython libraries, create dynamic objects, develop and use covariant and contravariant generic delegates, and more. For information about Visual C# language samples and how to access them, see Visual C# Sample Applications.

See Also

Reference

What's New in the Visual Studio Debugger

Concepts

What's New in Visual Studio 2010

What's New in the Visual Studio 2010 Editor

What's New in the .NET Framework 4

What's New in ASP.NET 4 and Visual Web Developer

What's New in Deployment