The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Archive for the ‘C# 3.0’ Category

Convert linq query to string array/list – C# – Stack Overflow

Posted by jpluimers on 2011/04/19

Sometimes little snippets of code help you big time.

Note the below ones are not performant (they will load all the data), but can make your code a lot more readable.

Use with care!

return list.Select(x => x.ToString()).ToArray();

return list.Select(x => x.ToString()).ToList();

–jeroen

via: Convert linq query to string array – C# – Stack Overflow.

Posted in .NET, C#, C# 3.0, C# 4.0, Development, LINQ, Software Development | Leave a Comment »

c# – List of new features in C#2.0, 3.0 and 4.0 – Stack Overflow

Posted by jpluimers on 2011/04/12

When maintaining software, you can’t always use the latest versions of your tools and languages.

Since C# has added a lot since version 1, it is handy to know what changed in which version.

Of course nothing beets the (paper and electronic!) editions of C# in Depth (covering C# 1, 2 and 3) and C# in Depth second edition (covering C# 2, 3 and 4).

Those books are thick (they need to, there is a truckload to cover!).
(The publisher (Manning) actually did a very good job on the e-book versions. Highly recommended, as it makes searching stuff so much easier).

The answers to the c# – List of new features in C#2.0, 3.0 and 4.0 Stack Overflow question contains a few concise lists of major changes in the language.

I really like the Bluffer’s Guide to C# 2, and the Bluffer’s Guide to C# 3 that Jon Skeet mentioned in his answer (and wish he wrote a Bluffer’s Guide to C# 4 as well), as they focus on some essential stuff in a very concise way.

If you want more detailed info, start with these stackoverflow questions:

Since stackoverflow wasn’t there when C# 2 was introduced in 2005, start with this nice C# 2 overview article on CSharpCorner.

Note: contrary to popular belief, there is no C# 3.5. There is .NET 3.5 (adding LINQ) and .NET 3.0 (adding WPF, WCF and WF) all based on the C# 3.0 and CLR 2 SP1 features.
(Yes, some expression tree features don’t work on CLR2 RTM, as that one has a few bugs, see Jared’s comment on this answer).

--jeroen

via: c# – List of new features in C#2.0, 3.0 and 4.0 – Stack Overflow.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Jon Skeet, Software Development | Leave a Comment »

Recommended blog post: Favorite C# Idioms | Blue Onion Software

Posted by jpluimers on 2011/04/05

While browsing for some less used but useful C# features, I came across a great post by Michael (Mike) Ward from Blue Onion Software on Favorite C# Idioms based on the great Hidden Features of C# thread on StackOverflow.

Mike starts with

There’s a great post on Stackoverflow about hidden features in C#. I prefer to think of these as idioms rather than hidden features since most are actually documented. Here are my favorites.

Then he continues with some nice examples of C# idioms.

Recommended reading!

–jeroen

via Favorite C# Idioms | Blue Onion Software.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development | Leave a Comment »

Solution for “Why do I get a ‘LoaderLock’ Error when debugging my Managed DirectX application” (The ZBuffer)

Posted by jpluimers on 2011/03/17

I maintain some .NET code that still uses the MDX 1.1 (since MDX 2.0 got cancelled, and this project cannot be brought to XNA).

Every now and then, you get a Loader Lock error.

ZBfufer provides the solution (I always use choice ): Read the rest of this entry »

Posted in .NET, C#, C# 2.0, C# 3.0, Development, Software Development, Visual Studio 2005, Visual Studio 2008, Visual Studio and tools | Leave a Comment »

Exception Filter – VB.NET supports this, but not C#, so write a VB.NET wrapper to expose it to C#

Posted by jpluimers on 2011/02/24

Often I explain to people that there are a lot of .NET languages, because the .NET IL is rich, so the individual languages can focus on the IL pieces they do best.

This also means, that most languages have some support for specific pieces of IL that other languages do not have support for.

The IL Exception Filter feature is one such thing. It is supported by for instance VB.NET but not by C# as Junfeng Zhang explains:

C# does not support exception filter. However, VB and IL support it. To add exception filter to C#, we can build a function in VB or IL, then call it in C#.

Read his full article for the complete code.

–jeroen

via: Exception Filter – Junfeng Zhang’s Windows Programming Notes – Site Home – MSDN Blogs.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development, VB.NET | Leave a Comment »

Supporting Office 2003 from .NET: getting the Office 2003 Primary Interop Assemblies

Posted by jpluimers on 2011/02/22

Often you work with projects not having the latest stuff.
Sometimes that is a good thing: latest stuff is not always best :-)

In this case, the client had Office 2003, and needed to do some Excel automation from .NET.
The development systems however had Office 2007 on it, so importing Excel defaults to the Office 2007 Primary Interop Assembly: Office version 12 in stead of 11. Read the rest of this entry »

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Delphi, Development, Prism, Software Development, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »

Verifying if two hosts are on the same IPv4 network

Posted by jpluimers on 2011/02/17

Recently, I wrote a bunch of code both in C# and Delphi to verify if two hosts are on the same IPv4 network.

Even though the public IPv4 address space is exhausted (IANA recently allocated the final two IPv4 blocks of their primary pool to APNIC, then allocated the five remaning /8 IPv4 blocks to the RIRs, thereby depleting the IPv4 pool), they are still used a lot, especially in private networks.

Over the next couple of weeks, you will see a couple of blog posts explaining:

  • how to get the IPv4 addresses and network masks of network interfaces in your computer
  • how to convert those to and from strings
  • how to convert a host-name to a list of IP addresses
  • how to lookup the current host-name
  • how network masks are related to counting leading/trailing ones and zeros
  • how to compare two IPv4 addresses given they have the same network masks

Those blog posts will have sample code in both Delphi and C#. And there will be unit tests to verify the underlying code.

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Delphi, Development, Software Development | 2 Comments »

some good tips on C# Excel Interop Use from Sam Allen

Posted by jpluimers on 2011/02/16

Each time I need to do Office COM interop, I wish they had overloaded methods: all those Type.Missing entries, and speed issues.

I know C# 4.0 makes missing parameters easier, but a lot of projects are not yet in Visual Studio 2010.

So this C# Excel Interop Use page by Sam Allen comes in handy.

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, Development, Software Development | Leave a Comment »

Stack Overflow ebooks

Posted by jpluimers on 2011/02/10

Greg Hewgill published a bunch Stack Overflow ebooks and StackExchange stats.
His readme explains a bit more on the books.
The blog he maintains makes up for some nice reading too.
Be sure to read the blog entry on the ebooks.

–jeroen

via Stack Overflow ebooks.

Posted in *nix, .NET, ASP.NET, C#, C# 2.0, C# 3.0, C# 4.0, Database Development, Delphi, Delphi for PHP, Development, HTML, HTML5, Java, Pingback, Power User, RegEx, Scripting, SocialMedia, Software Development, SQL, SQL Server, Stackoverflow, XML/XSD | Leave a Comment »

Visual Studio 2010: macro to change Target Framework Version for solution (by Scott Dorman)

Posted by jpluimers on 2010/05/21

Scott Dorman udpated his macro to change the target framework version for all projects in a solution to Visual Studio 2010 and published the new macro on CodeProject.

His new macro now supports these target frameworks:

Notes:

  • The links are to the download pages of the frameworks; look for “Standalone version” or “Full installer” for non-bootstrap download.
    (version 1.1 can be downloaded here, but is not supported in VS2010)
  • The “Client Profile” versions are stripped down versions of their “Full” counterpart.

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Delphi, Development, Prism, Software Development, Visual Studio and tools | 2 Comments »