Site: http://blogs.msdn.com/b/csharpfaq/archive/category/7581.aspx Link: http://blogs.msdn.com/csharpfaq/rss.aspx?CategoryID=7581
by Alexandra Rusina via C# Frequently Asked Questions : on 6/1/2010 5:33:00 PM
With this post I want to start a series devoted to the new parallel programming features in .NET Framework 4 and introduce you the Task Parallel Library (TPL). I have to admit that I’m not an expert in multithreading or parallel computing. However, people often ask me about easy introductions and beginner’s samples for new features. And I have an enormous advantage over most newbies in this area – I can ask people who developed this library about what I’m doing wrong and ...
[ read more ]
by Alexandra Rusina via C# Frequently Asked Questions : on 5/10/2010 6:50:00 PM
After a quick review of C# language features, let’s do the same for the IDE improvements. So, what’s in there for C# developers? Generate From Usage This feature greatly improves Visual Studio support for test-driven development (TDD). However, it is useful even if you don’t use TDD at all. It might increase your productivity by simply reducing the number of keystrokes and eliminating repetitive typing. For example, now I can write code like this: class Program{ static v ...
by Alexandra Rusina via C# Frequently Asked Questions : on 4/12/2010 9:30:00 AM
Visual Studio 2010 is here! And of course this means that C# 4.0 is also here. Let’s do a quick review of the new language features added in this release. Dynamic The dynamic keyword is a key feature of this release. It closes the gap between dynamic and statically-typed languages. Now you can create dynamic objects and let their types be determined at run time. With the addition of the System.Dynamic namespace, you can create expandable objects and advanced class wrappers, and you can provide i ...
by Alexandra Rusina via C# Frequently Asked Questions : on 3/11/2010 9:44:35 PM
This is a follow-up to the Getting Information About Objects, Types, and Members with Expression Trees post, so I would recommend that you read that one first. Among other code examples in that blog post, I demonstrated how you can get a property name as a string by using expression trees. Here is the method. public static string GetName<T>(Expression<Func<T>> e) { var member = (MemberExpression)e.Body; return member.Member.Name; } And here is how you can use it. s ...
by Alexandra Rusina via C# Frequently Asked Questions : on 1/25/2010 7:17:00 PM
Let’s take a quick look at the object keyword first. I’m not going to talk a lot about it because it’s been around since C# 1.0. This keyword is nothing more than a shortcut for System.Object, which is the root type in the C# class hierarchy. (However, as Eric Lippert pointed out in his blog post, not everything in C# derives from object.) This is a powerful mechanism, since you can assign almost any value to instances of this type. Here is a short example that demonstrates some of the benefits ...
by Alexandra Rusina via C# Frequently Asked Questions : on 1/6/2010 7:49:00 PM
Starting with C# 3.0 and Visual Studio 2008, you can use expression trees to get information about objects, types, and members. In this post I’m going to show some examples and explain what benefits you can get by using this technique. If you are not familiar with expression trees, I would recommend reading Charlie Calvert’s blog post Expression Tree Basics first. Let’s start with a simple task. Assume that you want to print the name of a field or a property next to its value. For example, imagi ...
by Alexandra Rusina via C# Frequently Asked Questions : on 11/19/2009 8:05:00 PM
First of all, let’s take a look at the example from one of my previous posts. It creates an expression tree for calculating the factorial of a number.ParameterExpression value = Expression.Parameter(typeof(int), "value"); ParameterExpression result = Expression.Parameter(typeof(int), "result"); LabelTarget label = Expression.Label(typeof(int)); BlockExpression block = Expression.Block( new[] { result }, Expression.Assign(result, Expression.Constant(1)), Expression.Loop( ...
by Alexandra Rusina via C# Frequently Asked Questions : on 10/19/2009 9:24:00 PM
In the previous post I showed how you can use the new dynamic feature and the ExpandoObject class to add and remove properties at run time, and how this can make your code more readable and flexible than code written with LINQ to XML syntax. But there were some obvious flaws in that example: While ExpandoObject provided better syntax, LINQ to XML provided a lot of useful library methods that helped you to work with XML files. So, is it possible to combine those two advantages, to have better sy ...
by Alexandra Rusina via C# Frequently Asked Questions : on 9/30/2009 11:49:00 PM
You have probably already heard about the new dynamic feature in C# 4.0 and how it is used to support COM interop. If you haven't, I strongly recommend reading the following MSDN articles: Using Type dynamic and How to: Access Office Interop Objects by Using Visual C# 2010 Features. Well, where else can you use this new feature? What are the use cases? Where does dynamic dispatch work better than static typing? The quick answer is that whenever you see syntax like myobject.GetProperty("Address ...
by CSharpFAQ via C# Frequently Asked Questions : on 1/27/2009 12:36:00 AM
Let’s start with the basics and maybe repeat some information that many of you already know. One of the most important concepts in LINQ performance and optimization is, of course, deferred execution. It simply means that when you declare a variable and assign it a query expression, that expression is not executed immediately. // Query is not executed. var query = from item in storage select item; The variable query now stores the command, and the query execution is deferred until ...
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.