Browse by Tags

Debugging Expression Trees in Visual Studio 2010
19 November 09 08:05 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 Read More...
Dynamic in C# 4.0: Creating Wrappers with DynamicObject
19 October 09 10:24 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 Read More...
Dynamic in C# 4.0: Introducing the ExpandoObject
01 October 09 12:49 AM
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 Read More...
Generating Dynamic Methods with Expression Trees in Visual Studio 2010
14 September 09 06:37 PM
Expression trees first appeared in Visual Studio 2008, where they were mainly used by LINQ providers. You can use expression trees to represent code in a tree-like format, where each node is an expression. You can also convert expression trees into compiled Read More...
How to use LINQ methods to compare objects of custom types
25 March 09 01:23 PM
LINQ provides a convenient syntax and many useful methods for operating with collections of objects. However, to be correctly processed by LINQ comparison methods such as Distinct or Intersect , a type must satisfy certain requirements. Let’s take a look Read More...
Postedby CSharpFAQ | 4 Comments    
Filed under: ,
Does the “LINQ to Objects” provider have built-in performance optimization?
26 January 09 04:36 PM
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 Read More...
Postedby CSharpFAQ | 1 Comments    
Filed under: ,
How do I send out simple debug messages to help with my debugging?
09 October 06 11:19 AM
Visual Studio offers tons of useful debugging features and allows you to step through your code line-by-line. However, there are times when you don’t want to step through your application, but want to make it output simple text strings with variable values, Read More...
Postedby CSharpFAQ | 1 Comments    
Filed under:
How do I calculate a MD5 hash from a string?
09 October 06 11:15 AM
It is a common practice to store passwords in databases using a hash. MD5 (defined in RFC 1321 ) is a common hash algorithm, and using it from C# is easy. Here’s an implementation of a method that converts a string to an MD5 hash, which is a 32-character Read More...
Postedby CSharpFAQ | 4 Comments    
Filed under:
How do I play default Windows sounds?
27 March 06 07:03 PM
Sometimes, you might want to make your application a bit more audible. If you are using .NET 2.0, you can utilize the new System.Media namespace and its SystemSound and SystemSounds classes. The SystemSounds class contains five static properties that Read More...
Postedby CSharpFAQ | 2 Comments    
Filed under:
How can I easily log a message to a file for debugging purposes?
27 March 06 06:59 PM
Often, you need a way to monitor your applications once they are running on the server or even at the customer site -- away from your Visual Studio debugger. In those situations, it is often helpful to have a simple routine that you can use to log messages Read More...
Postedby CSharpFAQ | 8 Comments    
Filed under:
How can I speed up hashtable lookups with struct object as keys?
20 March 06 06:54 PM
When you have struct objects as the key in a hashtable, the lookup operation of the hashtable performs miserably. This can be attributes to the GetHashCode() function which is used internally to do the lookup. If a struct contains only simple value types Read More...
Postedby CSharpFAQ | 21 Comments    
Where can I find design and coding guidelines for .NET?
21 February 05 01:30 PM
tipu_77 asked "What are microsoft suggested naming conventions in C#?" The .NET Framework Team collects their recommendations at their GotDotNet community site . which points to a fairly comprehensive MSDN page Design Guidelines for Class Library Developers Read More...
Postedby CSharpFAQ | 5 Comments    
What does the /target: command line option do in the C# compiler?
04 December 04 11:33 PM
All the /target: options except module create .NET assemblies. Depending on the option, the compiler adds metadata for the operating system to use when loading the portable executable (PE) file and for the runtime to use in executing the contained assembly Read More...
Postedby CSharpFAQ | 5 Comments    
What is the difference between const and static readonly?
03 December 04 05:13 PM
The difference is that the value of a static readonly field is set at run time, and can thus be modified by the containing class, w hereas the value of a const field is set to a compile time constant. In the static readonly case, the containing class Read More...
Postedby CSharpFAQ | 8 Comments    
How do I create a constant that is an array?
03 December 04 09:33 AM
Strictly speaking you can't, since const can only be applied to a field or local whose value is known at compile time. In both the lines below, the right-hand is not a constant expression (not in C#). const int [] constIntArray = newint [] {2, 3, 4}; Read More...
Postedby CSharpFAQ | 6 Comments    
More Posts Next page »

This Blog

Syndication

Page view tracker