C# 7 Series, Part 4: Discards

Sometimes we want to ignore values returned from a method, especially those out arguments, a typical example is to check whether a string can be parsed to another type: bool parsedValue;if (bool.TryParse(“TRUE”, out parsedValue)) { /* Do your stuff */ } Here we want to ignore parsedValue. We also want to make this variable inaccessible…

6

C# 7 Series, Part 3: Default Literals

C#’s default keyword has two kinds of usages: one is to label the fallback branch of the switch…case structure (for any path that does not fall into the case conditions); another is to represent the “default” value of a type. I will discuss this usage in this blog. The default value of a type is…

9

C# 7 Series, Part 2: Async Main

As you may know, there are two kinds of the programs the C# language can build. One is a program with an entrypoint so that the Operating System can load the program and execute it from the entrypoint; another is the program without an entrypoint. Operating System cannot directly execute the program, the program can…

12

C# 7 Series, Part 1: Value Tuples

Starting today I will start a new C# 7 series, to introduce new language features of C# 7+ features. Please note that I am not saying C# 7.0, I am saying C# 7 plus, because there will be minor language versions (like 7.1, 7.2) that will bring new features in steps (thanks to Roslyn!) such…

5

Code or Codes?

I’ve heard many people in Singapore are talking their work like this way: “Oh, I have some codes checked in, please find the error list of the error code that this service will return.” I have to say, when you are talking about the program that you have worked out, you should treat the noun…

1

Ad-hoc pagination support with SQL Server codenamed “Denali”

Microsoft has announced the Community Technology Preview (CTP) of its next generation SQL Server product, codenamed “Denali” several months. SQL Server “Denali” has many new features and enhancements, including these for the programmability and manageability features which you may interest in: Visual Studio 2010 based Management Studio tools Advanced T-SQL debugging support Code snippets and…

0

The Asynchronous Programming Models

An important new feature of C# 5.0 that comes with Visual Studio 11 is the async and the await keywords. They are syntactical sugars that simplifies the construction of asynchronous operations code. When the C# compiler sees an await expression, it generates code that automatically invokes the expression asynchronously, then immediately return the control flow…

1

Use dynamic type in Entity Framework 4.1 SqlQuery() method

As the release of Entity Framework 4.1, the DbContext.Database.SqlQuery() method offers a way to execute a SQL command then maps the returning result set to a strong typed object or a list of strong typed objects. However, if you want to use the dynamic type or anonymous type as its return type, you will probably…

1

Why no ForEach method on IEnumerable interfaces

I was asked many times recently regarding this topic, why not Microsoft introduce an extension method ForEach() on interface IEnumerable<T>? The answer is: "No, and never". Here are some strong reasons to not bring this extension method on IEnumerable. I will be discussing the following design considerations in this post. Design pattern Consistency Runtime behavior…

6

Welcome to my new place

I have decided to move my Tech Blog from http://www.markzhou.com/blog to http://blogs.msdn.com/b/mazhou. The new blog service is hosted by Microsoft, it provides more features to have a better blog reading and integration experience. The legacy blog URL will continue to work, but it will automatically redirect to the new blog address. MSDN blog hosting has…

0