DCSIMG
C# - עומר.נט

Browse by Tags

All Tags » C# (RSS)

My View of C# 4.0

Posted Oct 29 2008, 02:16 AM by עומר ון קלוטן  

I've known a bit about C# 4.0 for a while now and have had time to think about it. I've just re-read the New features in C# 4.0 paper published by Microsoft and would like to offer the following critique of the language's new features: Dynamic Lookup This feature just makes me cringe, just...
תגים:

Announcing New C# 4.0 LINQ Features and Book

Posted Aug 29 2008, 01:12 PM by עומר ון קלוטן  

* Fabrice Marguerie , co-author of LINQ In Action , asked me to clarify that this post has absolutely nothing to do with their book and is simply meant in jest * LINQ has been around for quite a while, making our lives easier with its short, declarative syntax. During talks in closed sessions, the persons...
תגים:,

Throw Before You Yield

Posted Aug 25 2008, 10:23 PM by עומר ון קלוטן  

In a comment left by Bart De Smet , he pointed out that I failed to address the fact that the execution of all "yielding" methods is deferred. For instance, when running the following code, no exceptions will be thrown: int [] arr = null ; var copy = arr.Enumerate(); // ... static IEnumerable...
תגים:

Pitfall: Static Field Inline Initialization Order of Execution

Posted Aug 19 2008, 05:09 PM by עומר ון קלוטן  

Here's something I fell into today. You have a class that has some members that need to be calculated once. So you use static readonly fields. One of those members is a calculation of some of those members. Take the following code for instance: public class StaticDemo { static readonly int Sum =...
תגים:

Extension Methods Roundup: Remove, Aggregate, At, AsIndexed and Friends

Posted Jun 19 2008, 10:28 PM by עומר ון קלוטן  

Hey hey hey! It's time for another Extension Methods Roundup! Here are some of the extension methods I've written since the last one: Dictionary's Missing Remove Methods public static void Remove<TKey, TValue>( this IDictionary <TKey, TValue> dictionary, TValue value) { // Check...

Breadth Recursion - a yield Solution to Post's Correspondence Problem

Posted Jun 06 2008, 11:07 PM by עומר ון קלוטן  

Post's Correspondence Problem (the other PCP) is a computer science problem, in which you have (and I simplify matters) a set of tiles, each having any number of letters on them from a preset group. For instance, you may have the tiles: The idea is to create a sequence of tiles (when you can use...

LINQ Performance Pitfall - Deferred Execution

Posted May 27 2008, 10:37 PM by עומר ון קלוטן  

When using LINQ, queries may bloat up to dozens of lines. My personal style is to take these queries and break them apart to smaller units of logic. To each unit of logic, I append a call to ToArray . @yosit asked me why I did it and I answered I was avoiding a possible pitfall. Here's what I meant...
תגים:,

Extension Methods Roundup: IndicesWhere, TakeEvery, Distinct

Posted May 18 2008, 04:14 PM by עומר ון קלוטן  

As I do from time to time, here is a batch of three Extension Methods I've written recently: IndicesWhere /// <summary> /// Gets the indices where the predicate is true. /// </summary> public static IEnumerable < int > IndicesWhere<T>( this IEnumerable <T> enumeration...

A Limitation of Lambda Expressions and Overloaded Extension Methods

Posted May 07 2008, 03:07 PM by עומר ון קלוטן  

Tamir hates lambdas. He was having a problem with one of his lambda expressions and twittered about it. Around that time I opened my twitter account (yes, Yosi finally convinced me) and offered my help. He wanted to have a single extension method that could iterate over a collection and either change...
תגים:,

Linq: The Missing ToDictionary Extension Method Overload

Posted Apr 22 2008, 04:20 PM by עומר ון קלוטן  

Enumerating over a Dictionary<TKey, TValue> you will get structs of type KeyValuePair<TKey, TValue> . Whenever you use the ToDictionary extension method, you are forced to specify how to get the key and value for each item, even if it's an enumeration of KeyValuePair s. Seems a bit redundant...

Linq: SequenceSuperset

Posted Apr 22 2008, 03:46 PM by עומר ון קלוטן  

Here's another Linq method I wanted to share. This one takes two enumerations, enumeration and subset and checks to see whether subset exists in enumeration in its original order. I used the naming convention set by SequenceEqual . Examples: enumeration = (1, 2, 3, 4, 5); subset = (3, 4) ==> SequenceSuperset...

Linq: ContainsAtLeast and AggregationOrDefault

Posted Apr 06 2008, 08:51 AM by עומר ון קלוטן  

I've created a couple of useful extension methods that I like to use with Linq, so here they are: ContainsAtLeast I've noticed that there's no way to find out whether a collection has at least X items. The following takes the collection, tries to take X items from it and asks whether it succeeded...

C# Feature Request: Type Member Level Generic Constraints

Posted Apr 02 2008, 11:57 AM by עומר ון קלוטן  

The Basic Need Take the following code: public abstract class Base { protected Base( int something) { // ... } } public class Derived : Base { public Derived( int something) : base (something) { // ... } } public class Derived2 : Base { public Derived2( int something) : base (something) { // ... } }...
תגים:,

Releasing My Code Snippet Repository

Posted Dec 15 2007, 01:40 AM by עומר ון קלוטן  

Whenever I teach classes or do demos, I get asked about the C# code snippets I use in Visual Studio, so I decided to release them, if anyone would like to use them. I've created a project on CodePlex and I'll try to update it whenever I write a new one or update the old ones. Nothing to release...

DependencyPropertyChangedEventArgs? Think Again.

Posted Dec 10 2007, 11:39 AM by עומר ון קלוטן  

Delegate Contravariance is a really cool feature in C# that is often overlooked, mostly because it is so implicit and "obvious". Go read the example I linked to if you don't know what it is (it's a short one). The following code, however, will not compile, even though you'd expect...
תגים:,

More Posts Next page »