Click here to Skip to main content
14,977,850 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 2011
Wonde 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 2011
MBigglesworth79
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 2011
Ctznkane
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 2011
Kiran Sonawane
1 alternative  
A trick when using Array.Contains()
Please Sign up or sign in to vote.
14 Jun 2011
PSK_
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 2011
Luc Pattyn
This is an alternative to "L33t Tr4nsl4t0r (Leet Translator)".
Please Sign up or sign in to vote.
27 Jun 2011
charles henington
1 alternative  
Please Sign up or sign in to vote.
5 Jun 2011
JV9999
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 2011
Kim Togo
2 alternatives  
Code to change text to Leet
Please Sign up or sign in to vote.
14 Jun 2011
Tamir 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 2011
Kanwal Shehzad
How to avoid WPF TreeView SelectedItemChanged being called twice
Please Sign up or sign in to vote.
17 Jun 2011
VallarasuS
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 2011
Mukit, 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 2011
Joel Ivory Johnson
Peer Communication on Windows Phone 7
Please Sign up or sign in to vote.
2 Jun 2011
AlexCode
Using ResolveUrl without Page
Please Sign up or sign in to vote.
8 Jun 2011
Kunal Chowdhury «IN»
Silverlight 5 Features Local File System Access without using COM API
Please Sign up or sign in to vote.
10 Jun 2011
supercat9
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 2011
Mohammad A Rahman
Caching uses with Proxy pattern in C#
Please Sign up or sign in to vote.
12 Jun 2011
PeteBarber
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 2011
George 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 2011
charles henington
1 alternative  
Please Sign up or sign in to vote.
22 Jun 2011
Andrew Rissing
A simple trick to remove the delay of Thread.Sleep for unit testing.
Please Sign up or sign in to vote.
29 Jun 2011
Erich 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 2011
Ian 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 2011
Kim 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 2011
FDW
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 2011
Arik 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 2011
GAMerritt
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 2011
YDaoust
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 2011
MWBate
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 2011
leopard447
How to do distinct raw data population in a DataTable
Please Sign up or sign in to vote.
16 Jun 2011
Artem 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 2011
Artem Smirnov
A few tricks in using FubuMVC
Please Sign up or sign in to vote.
21 Jun 2011
SergeyT2
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 2011
ddthien
How to read choice values for Multi choice questions in a Survey
Please Sign up or sign in to vote.
26 Jun 2011
JP_Rocks
4 alternatives  
A tip to concatenate a set of strings using comma/pipe
Please Sign up or sign in to vote.
29 Jun 2011
Mohammad 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 2011
Philippe 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 2011
Ziad 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[^]
Please Sign up or sign in to vote.
3 Jun 2011
Anshul 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 2011
FDW
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 2011
supercat9
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 2011
GAMerritt
A C# method which encapsulates the comparison operators.
Please Sign up or sign in to vote.
6 Jun 2011
Mohammad 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 2011
Steinar 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 2011
EbenRoux
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 2011
Steve 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 2011
adolfobarallobre
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 2011
nainakarri
Debugger showing wrong source file when debugging in VS2005
Please Sign up or sign in to vote.
24 Jun 2011
FDW
I do think the approach is over complicated, but in some cases there may be (a small) benefit. As an alternative I would offer:First version (no common test):((Action)(() =>{ if (!Step1()) return; if (!Step2()) return;}))();Second version (common...

Current Participants

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

Kunal Chowdhury «IN»
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:




PSK_
Architect
India India
Its me Smile | :)
No Biography provided
AlexCode
Architect
Switzerland Switzerland
Senior IT Consultant working in Switzerland as Senior Software Engineer.

Find more at on my blog.
Andrew Rissing
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.
Anshul R
Student
India India
No Biography provided
Arik Poznanski
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).
Artem Smirnov
Software Developer GeekSoft
Lithuania Lithuania
No Biography provided
charles henington
United States United States
I do not claim to be wrong! I just rarely ever write.
Ctznkane
United States United States
No Biography provided
ddthien
United States United States
No Biography provided
EbenRoux
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.
Erich Ledesma
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
No Biography provided
GAMerritt
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.
George Swan
Student
Wales Wales
No Biography provided
Ian Good
Software Developer (Senior) Undead Labs
United States United States
No Biography provided
Joel Ivory Johnson
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

JP_Rocks
India India
No Biography provided
JV9999
Software Developer (Senior)
Netherlands Netherlands
No Biography provided
Kanwal Shehzad
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).
Kim Togo
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.
Kiran Sonawane
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
leopard447
Pakistan Pakistan
No Biography provided
Luc Pattyn
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.
MBigglesworth79
Web Developer
United Kingdom United Kingdom
No Biography provided
Mohammad Mir mostafa
Architect Iran
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided
Mukit, Ataul
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1
MWBate
Architect
Unknown
No Biography provided
nainakarri
India India
Developer
PeteBarber
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.
Philippe Mori
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.
SergeyT2
Software Developer
Russian Federation Russian Federation
No Biography provided
No Biography provided
Steve Roberson
Software Developer (Senior) SouthData, Inc.
United States United States
No Biography provided
supercat9
Web Developer
Unknown
Embedded systems programmer since 1994.
Tamir Khason
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.
VallarasuS
Technical Lead
India India
I code, learn, read and listen.
Wonde Tadesse
Architect
United States United States
MSCS, MCTS, Senior Software Engineer, Architect, Craftsman, The Ultimate DEV ...
Azure Series

YDaoust
CEO VISION fOr VISION
Belgium Belgium
No Biography provided
Ziad J.khan
Software Developer (Senior)
Mauritius Mauritius
No Biography provided
You must sign in to participate in this contest.
This contest has ended.
1 Jun - 30 Jun 2011