Click here to Skip to main content
15,946,342 members
This competition has ended

Best C# article of June 2011

Contribute to CodeProject and you'll automatically be in the running for a monthly prize!

Each month at CodeProject we gather together the best of the articles submitted the previous month and ask our readers to choose the best of the best. Entry is automatic - just submit you articke and we'll do the rest.

Check out the submission guidelines for information on posting articles.

Current Entries

Articles that match the contest criteria are automatically entered. The top 50 entries are shown.

Please Sign up or sign in to vote.
16 Jun 2011Wonde Tadesse
The other option will be to use Update Panel ASP.NET control as much as possible. It helps to retain the current position on the page whenever a postback happens to the page.
Please Sign up or sign in to vote.
4 Jun 2011MBigglesworth79
An introduction to Reflection in .NET as well as some examples of how it can be used.
Please Sign up or sign in to vote.
13 Jun 2011Ctznkane
The Array class already contains this capability with no casting required. The IndexOf method is a static one that returns the index of the value and a -1 if it doesn't exist.Here is an example:exists = Array.IndexOf(arr, "item") >= 0
Please Sign up or sign in to vote.
20 Jun 2011Kiran Sonawane 1 alternative  
A trick when using Array.Contains()
Please Sign up or sign in to vote.
14 Jun 2011PSK_ 1 alternative  
How to maintain scroll position of a long page with vertical scrollbar in browser other than IE.
Please Sign up or sign in to vote.
13 Jun 2011Luc Pattyn
This is an alternative to "L33t Tr4nsl4t0r (Leet Translator)".
Please Sign up or sign in to vote.
27 Jun 2011charles henington 1 alternative  
Please Sign up or sign in to vote.
5 Jun 2011JV9999
Not really, because what if your finally block would contain more lines of code than the single line you have in your example? That would make it already much harder to read.Secondly, you are misusing the Dispose method. You shouldn't invoke anything in it, especially not the Action, you...
Please Sign up or sign in to vote.
7 Jun 2011Kim Togo 2 alternatives  
Code to change text to Leet
Please Sign up or sign in to vote.
14 Jun 2011Tamir Khason
How to import OpenSSL private key into .NET application and use it with X509 public certificate to establish TLS connection with asymmetric encryption and two phase certificates handshake
Please Sign up or sign in to vote.
9 Jun 2011Kanwal Shehzad
How to avoid WPF TreeView SelectedItemChanged being called twice
Please Sign up or sign in to vote.
17 Jun 2011VallarasuS 1 alternative  
Here is how you can achieve Gradients used in Office 2010 Buttons with a glow at the bottom.
Please Sign up or sign in to vote.
26 Jun 2011Mukit, Ataul
This tip shows you how to create a delegate from a C++ function pointer
Please Sign up or sign in to vote.
28 Jun 2011Joel Ivory Johnson
Peer Communication on Windows Phone 7
Please Sign up or sign in to vote.
2 Jun 2011AlexCode
Using ResolveUrl without Page
Please Sign up or sign in to vote.
8 Jun 2011Kunal Chowdhury «IN»
Silverlight 5 Features Local File System Access without using COM API
Please Sign up or sign in to vote.
10 Jun 2011supercat9
If the right-hand operand of an assignment is a "new", there's no need to explicitly specify the type of the new variable being created unless the new variable will have to hold items of a more general type than the right-hand operand would indicate. I would consider the code clearer without the...
Please Sign up or sign in to vote.
12 Jun 2011Mohammad A Rahman
Caching uses with Proxy pattern in C#
Please Sign up or sign in to vote.
12 Jun 2011PeteBarber
It is critically important to make sure that a View's DataContext is properly created and attached before the underlying Window is displayed, otherwise initial events will be missed.
Please Sign up or sign in to vote.
15 Jun 2011George Swan
As it stands, the TryParse method will fail if the string contains commas. E.g., 10,000. To get around this, you can use:bool isnumber=int.TryParse(text,System.Globalization.NumberStyles.Integer | System.Globalization.NumberStyles.AllowThousands, ...
Please Sign up or sign in to vote.
15 Jun 2011charles henington 1 alternative  
Please Sign up or sign in to vote.
22 Jun 2011Andrew Rissing
A simple trick to remove the delay of Thread.Sleep for unit testing.
Please Sign up or sign in to vote.
29 Jun 2011Erich Ledesma
I rather like IEnumerable than IList, parameters should be as general as posible. I think it's really getting very fun up here. Here's my choice, just for strings.public static string Join(this IEnumerable parts, string separator){ if (! parts.Any()) return...
Please Sign up or sign in to vote.
2 Jun 2011Ian Good
I'm a fan of these guys... (Though I feel like I might catch some flack for the first one.)public static bool IsNullOrEmpty(this ICollection collection){ return collection == null || collection.Count == 0;}public static float Clamp(this float value, float low, float hi){...
Please Sign up or sign in to vote.
8 Jun 2011Kim Togo
I have tried to change the code with a good idea from Luc Pattyn (Thanks).The code is more compact, and I have tried to make the code more simple, that handles the degree selection.// Leet Translator - L33t Tr4nsl4t0r.// Version 2.//// Just for the fun.//using...
Please Sign up or sign in to vote.
9 Jun 2011FDW
This is what I would do:using System;using NUnit.Framework;using System.Reflection;namespace Profix.Utils.Xpo.UnitTests{ [TestFixture] public class Functions { private void Tax() { Console.WriteLine("Computed Tax."); } private void Sale() {...
Please Sign up or sign in to vote.
10 Jun 2011Arik Poznanski
“After the Deadline” provides a web based API for both grammar and spell checking, free for non-commercial use!
Please Sign up or sign in to vote.
12 Jun 2011GAMerritt
A C# method which rounds to the nearest multiple of a chosen power of an arbitrary base.
Please Sign up or sign in to vote.
14 Jun 2011YDaoust
What aboutpublic static string NUMthOF(UInt32 v){ return v.ToString() + // Append the ordinal suffix for the unit digit // unless the ten digit is a one (force 'th') "thstndrdthththththth".Substring(2 * (int)(v / 10 % 10 != 1 ? v % 10 : 0), 2);}?Now all...
Please Sign up or sign in to vote.
14 Jun 2011MWBate
I have been using the following code (suggested by someone on an MSDN forum) to determine if a default mail client has been configured:RegistryKey hkey = Registry.ClassesRoot.OpenSubKey( "mailto\\shell\\open\\command", false);hkey will be null if there is no such client.
Please Sign up or sign in to vote.
15 Jun 2011leopard447
How to do distinct raw data population in a DataTable
Please Sign up or sign in to vote.
16 Jun 2011Artem Smirnov
For those of you scared by the numerous steps required to setup a typical Open Source project, this would be a pleasant surprise.
Please Sign up or sign in to vote.
16 Jun 2011Artem Smirnov
A few tricks in using FubuMVC
Please Sign up or sign in to vote.
21 Jun 2011SergeyT2
You can use Action instead of MethodInvoker as well. And ".Invoke" at the method is unnesessary.public static void ThreadSafeCall(this Control control, Action method){ if (control.InvokeRequired) { control.Invoke(method); } else { method(); ...
Please Sign up or sign in to vote.
24 Jun 2011ddthien
How to read choice values for Multi choice questions in a Survey
Please Sign up or sign in to vote.
26 Jun 2011JP_Rocks 4 alternatives  
A tip to concatenate a set of strings using comma/pipe
Please Sign up or sign in to vote.
29 Jun 2011Mohammad A Rahman
The code has been updated to improve the performance:public static bool DoSequenceOfOr(params Func[] sequenceOfBooleanValue){ foreach (Func item in sequenceOfBooleanValue) if (item()) return true; return false;}public static bool...
Please Sign up or sign in to vote.
29 Jun 2011Philippe Mori
Instead of doing it yourself, a better way would be to use LINQ for that purpose. Here is an example for addition:int[] numbers = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };int result = numbers.Aggregate((x, y) => x + y).ToString());and for multiplication:long[] numbers = { 4, 5, 6, 7,...
Please Sign up or sign in to vote.
29 Jun 2011Ziad J.khan
You can find a much more advanced version of this here:http://univar.codeplex.com[^]The version provided on the download page is soon to be deprecated by the upcoming version 2.0b however. The latter is available here instead:http://univar.codeplex.com/SourceControl/list/changesets[^]
1 Jun 2011Accusoft
Traditional forms processing solutions have run on desktops or local servers. This whitepaper suggests an alternative approach: doing forms processing via a web service. This allows for processing forms through a browser, mobile forms processing, and access to forms processing from environments beyo
Please Sign up or sign in to vote.
3 Jun 2011Anshul R
public static bool IsNullEmptyOrWhitespace(this string value){ return string.IsNullOrEmpty(value) || string.IsNullOrEmpty(value.Trim());}In C# 4.0, you already have such a function.string.IsNullOrWhiteSpace(value)
Please Sign up or sign in to vote.
5 Jun 2011FDW
Here is a couple for String and StringBuilder. The String versions are handy (compared to the already existing instance versions (that are actually being used)) because they work against null values (e.g., ((string)null).IsNullOrEmpty()).public static class ExtensionMethodsString{ ...
Please Sign up or sign in to vote.
5 Jun 2011supercat9
There are times when "try"-related wrappers can be useful. For example, a Try() wrapper DLL written in a language other than C# could pass an Exception parameter to the Finally clause indicating whether the Try clause succeeded. For example:Try (() => {DoSomething();}, (Exception inner_ex)...
Please Sign up or sign in to vote.
5 Jun 2011GAMerritt
A C# method which encapsulates the comparison operators.
Please Sign up or sign in to vote.
6 Jun 2011Mohammad Mir mostafa
public static bool IsInString(this char c, string range){ return range.Contains(c.ToString());}public static bool IsInteger(this string text){ int num; return int.TryParse(text, out num);}public static bool IsNullOrEmpty(this string str){ return...
Please Sign up or sign in to vote.
13 Jun 2011Steinar Moen from Norway
This article describes an implementation on BizTalk 2006/R2/BizTalk 2009 where a received message is split and sent to many different destinations.
Please Sign up or sign in to vote.
14 Jun 2011EbenRoux
An alternative is to abstract the settings that you intend to use.So instead of changing your app.config on the fly, simply change a mock or the instance values of the configuration object.For example:public interface IApplicationConfiguration{ string MaybeAFolderINeed { get; } ...
Please Sign up or sign in to vote.
14 Jun 2011Steve Roberson
This version treats the input string as an indexed string. The code is a little shorter.private string createDisplayText(string propertyName){ if (String.IsNullOrEmpty(propertyName)) { return String.Empty; } StringBuilder builder = new StringBuilder(); ...
Please Sign up or sign in to vote.
20 Jun 2011adolfobarallobre
Here is code for an alternate:public class OfficeButton : Button{ public OfficeButton() : base() { } private Color mGradientGlowColorColor; // the Color field public Color GradientGlowColor // the Color property { get { return...
Please Sign up or sign in to vote.
24 Jun 2011nainakarri
Debugger showing wrong source file when debugging in VS2005

Current Participants

Those with articles that match the contest criteria are automatically entered.

Technical Lead
India India

Kunal Chowdhury is a former Microsoft "Windows Platform Development" MVP (Most Valuable Professional, 2010 - 2018), a Codeproject Mentor, Speaker in various Microsoft events, Author, passionate Blogger and a Senior Technical Lead by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows app development. He posts his findings, articles, tutorials in his technical blog (www.kunal-chowdhury.com) and CodeProject.


Books authored:


Connect with Kunal on:




Architect
India India
Its me Smile | :)
United States United States
Accusoft provides a full spectrum of document, content, and imaging solutions as fully supported, enterprise-grade, client-server applications, mobile apps, cloud services, and software development kits. The company is focused on solving document lifecycle complexities through:


- A customer-focused approach
- Continuous product development
- Proactive support
- Forward-thinking leadership

Founded in 1991, Accusoft has grown through persistent product innovation and strategic mergers and acquisitions into the best-in-class solutions provider it is today. The company has been awarded 30 patents and is recognized as a thought leader in the industry.
This is a Organisation

1 members
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Architect
Switzerland Switzerland
Senior IT Consultant working in Switzerland as Senior Software Engineer.

Find more at on my blog.
Architect
United States United States
Since I've begun my profession as a software developer, I've learned one important fact - change is inevitable. Requirements change, code changes, and life changes.

So..If you're not moving forward, you're moving backwards.
Student
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).
Software Developer GeekSoft
Lithuania Lithuania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
United States United States
I do not claim to be wrong! I just rarely ever write.
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Architect
South Africa South Africa
If you are interested in Domain-Driven Design you may be interested in my [Hard Edges](https://www.amazon.com/Hard-Edges-Practical-Domain-Driven-Design-ebook/dp/B076W428NG) book.

I also have a [YouTube channel](https://www.youtube.com/channel/UCtaK4nTyVCs7rc5uEul6zZw) and some repositories over on [GitHub](https://github.com/Shuttle).

Documentation:

- [Shuttle.Esb service bus](http://shuttle.github.io/shuttle-esb/)
- [Shuttle.Core infrastructure / service hosting](http://shuttle.github.io/shuttle-core/)
- [Shuttle.Recall event sourcing (experimental)](http://shuttle.github.io/shuttle-recall/)

I have over 20 years of experience in the professional arena as a developer, consultant, and architect within many industries and have provided strategies and solutions that have contributed to the successful implementation of various systems. I believe firmly in the development of quality software that empowers users to get their job done.

My current focus is on domain-driven design implemented within an event-driven architecture based on message-oriented middle ware.
Architect SunHotels
Spain Spain
I Received a Bachelor's Degree in Computer Science at the Mathematics and Computer Science Faculty, University of Havana, Cuba.

I mainly work in web applications using C# and some Javascript. Some very few times do some Java.
FDW
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
United States United States
Writer, designer, inventor, musician, observer, and critic with many years of experience in each of these areas. I can do without the approval of "experts" because I believe candid statements and penetrating analysis bring greater rewards than a "pat on the back". And if I have something to say when you're not listening, I tell someone else about it.
Student
Wales Wales
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer (Senior) Undead Labs
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering. I've largely developed solutions that are based on a mix of Microsoft technologies with open source technologies mixed in. I've got an interest in astronomy and you'll see that interest overflow into some of my code project articles from time to time.



Twitter:@j2inet

Instagram: j2inet

India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer (Senior)
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer (Senior) Al Kaffary
Saudi Arabia Saudi Arabia
I am Computer Science graduate and working in Microsoft technologies (VB.Net/C#, ASP.Net, WPF, WCF, SQL Server 2005/2008, Web Services).
Software Developer Miralix
Denmark Denmark
Has worked as a programmer since 1999, starting with C++/MFC, Java, PHP and MySQL. Now it is all about C# (my favorite programming language), MS SQL, Azure and Xamarin (iOS/Android/WP8)

My primary work is to create applications that interacts with PABC/PBX, Microsoft Lync / UCMA.
Team Leader iNautix Technologies
India India
I am microsoft professional having about 8 years of experience on web technologies and working as TechLead. I am self starter guy and proficient in asp.net, web & wcf service. Try to learn something new everyday, this is how I work. In my 8 years of experience I worked with Microsoft technology, PHP, classic ASP, Cold Fusion and Ruby on Rails
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer (Senior)
Belgium Belgium
I am an engineer with a background in electronics, software and mathematics.

I develop technical software, both for embedded systems and for desktop equipment. This includes operating systems, communication software, local networks, image processing, machine control, automation, etc.

I have been using all kinds of microcontrollers and microprocessors (Intel 4004/8080/8051/80386/Pentium, Motorola 680x/680x0/ColdFire/PowerPC, Microchip PIC, Altera NIOS, and many more), lots of programming languages (all relevant assemblers, Fortran, Basic, C, Java, C#, and many more), and different operating systems (both proprietary and commercial).

For desktop applications and general development tools I have been using both UNIX systems and Mac/MacOS for many years, but I have switched to x86-based PCs with Windows, Visual Studio and the .NET Framework several years ago.

I specialize in:
- cross-platform development (making software that runs on diverse hardware/OS combinations)
- instruction set simulation
- improving software performance, i.e. making sure the software runs the job at hand in as short a time as possible on the given hardware. This entails algorithm selection, implementation design, accurate measurements, code optimisation, and sometimes implementing virtual machines, applying SIMD technology (such as MMX/SSE), and more.
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer
Australia Australia
Architect Iran
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1
Architect
Unknown
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
India India
Developer
Team Leader
United Kingdom United Kingdom
My day job is mostly working in C++ with a bit of C#. I write a fair amount of command line based tools and really wish they could have a GUI front-end to them hence why I spend my spare time working with WPF.

I started a blog few years back but didn't do a lot with it. I've started describing some of the interesting programming things I come across on it. Please take a look.
Software Developer (Senior)
Canada Canada
Programmer at Maid LABS from 2003 (www.maidlabs.com)

Programmer-Analyst at Viasat Geo Technoligies from 1995 to 2002 (www.viasat-geo.com).

I have studied at École Polytechnique de Montréal in computer engineering.
Software Developer
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer (Senior) SouthData, Inc.
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Web Developer
Unknown
Embedded systems programmer since 1994.
Architect Better Place
Israel Israel
Hello! My name is Tamir Khason, and I am software architect, project manager, system analyst and [of course] programmer. In addition to writing big amount of documentation, I also write code, a lot of code. I used to work as a freelance architect, project manager, trainer, and consultant here, in Israel, but recently join the company with extremely persuasive idea - to make a world better place. I have very pretty wife and 3 charming kids, but unfortunately almost no time for them.

To be updated within articles, I publishing, visit my blog or subscribe RSS feed. Also you can follow me on Twitter to be up to date about my everyday life.
Technical Lead
India India
I code, learn, read and listen.
Architect
United States United States
MSCS, MCTS, Senior Software Engineer, Architect, Craftsman, The Ultimate DEV ...
Azure Series

CEO VISION fOr VISION
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Software Developer (Senior)
Mauritius Mauritius
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
You must sign in to participate in this contest.
This contest has ended.
1 Jun - 30 Jun 2011