The history of 1.c# language

Source: Internet
Author: User

The history of 1.c# language

This section provides a brief introduction to the new language features from c#1 to c#5 versions.

1. Simple data types

Let's first write a product class using C#1, as shown in

strongly-typed collections in c#2 (generics)

C#3 automatic implementation of attributes and simplified initialization

C#4 named parameters

The above is a summary of the evolution of the product class from c#1 to C#4 as follows:

2. Sorting and filtering

sorting function

Below we will use the Product object by name to sort through the improvements to the sorting.

Sorting in the C#1

Sorting in c#2 (generics are introduced)

Sorting in C # 3 (lambda expression)

The following summarizes the evolution of the process of c#1-c#3 in the process of sequencing

3. List Query

Here's a look at all the items price>250 in the product list.

C#1 's Query

Problem in c#1: forced type conversion in c#1, using if loop to determine

Queries in C#2 (introducing generics to avoid coercion of type conversions)

Use if to judge unprofessional, delegate can be used in c#2, and print and query will be separated

The above code is optimized as follows, but the delegate still looks cumbersome

C#3 using LAMDBA expressions for optimization

Summarize

4. Handling Unknown data

Nullable Types

Scenario for handling unknown data: If the value of the price object in the product class in the database can be null, but it is a value type in the object, the value type cannot be null.

There are three ways to handle c#1:

1. Creating a reference type wrapper around decimal

2. Maintain a bool type value to indicate whether he is null

3. Use "magic number" to represent an unknown price

C#2 uses the nullable type nullable<t> structure provided by. Net 2.0, and provides syntax for sugar simplification work

readonly decimal price;

Optional parameters and default values

In C#1, c#2, c#3 you must use the overloads of the method if you do not want to provide all the method parameters externally.

However, "optional parameters" are introduced in the C#4

5.LINQ Introduction

LINQ is the core of c#3, and LINQ is about querying, with the goal of using consistent syntax and features to make querying multiple data sources simple in an easy-to-read, composable way.

Query Expressions

The data source is a list of objects

For example: Search for product name and supplier name with unit price greater than 100

var is the type that is inferred from the result when the program compiles, type inference

Query XML

The data source is an XML file

Linq to Sql

When the data source is a database, it is written like an object-based list, which is explained in more detail later.

6.com and dynamic types

One of the most important things in c#4 is interoperability, which includes two major topics dealing with old COM technologies and mapping dynamic

Com:component Object model,c#4 simplifies COM interop, supports indexers

Dynamic type: A new type, for the C # compiler is a type that the CLR does not recognize at all, and is used for more dynamic language interaction.

7. Async Code

C#5: An asynchronous function that can use an asynchronous function to break code execution without blocking the thread.

Async:async is actually a token that marks this method as an async method. When a method is marked as an async method, the await keyword must be used in its method.

Await

8..net Platform Introduction

The history of 1.c# language

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.