Click here to Skip to main content
14,977,821 members
This competition has ended

Best C# article of February 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.
9 Feb 2011
Robert Rohde
This one should outperform both the other methods for longer strings because of the StringBuilder.string s = "AbCdEfGhI§$%&/()1234567890";var sb = new StringBuilder(s.Length);foreach (char c in s) sb.Append(char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c));s =...
Please Sign up or sign in to vote.
6 Feb 2011
Brij
Why textbox persists data during postback even if View State set to off
Please Sign up or sign in to vote.
12 Feb 2011
Sandeepkumar Ramani
Parallelism in .NET – PLINQ
Please Sign up or sign in to vote.
8 Feb 2011
OriginalGriff
When I add a log reader, the size of the log can be huge, and get very slow to view. This makes the GridView do all the work of paging the data for you.
Please Sign up or sign in to vote.
19 Feb 2011
#realJSOP
2 alternatives  
Determine the number of unique colors in an image
Please Sign up or sign in to vote.
3 Feb 2011
Inaki Ayucar
How to get exactly what you need using DirectoryInfo.GetFiles, with an exact extension match lookup
Please Sign up or sign in to vote.
9 Feb 2011
#realJSOP
StringBuilder mystring = new StringBuilder("AbCd");for (int i = 0; i
Please Sign up or sign in to vote.
16 Mar 2011
Abhishek Sur
Get Reflected use TypeDescriptor
Please Sign up or sign in to vote.
14 Feb 2011
Shailendra P Singh
This article explains the auto-deployment of build using Microsoft Web deploy on build quality change event of TFS 2010
Please Sign up or sign in to vote.
23 Feb 2011
jasonalls
The solution in this tip will enable you to delete SSL certificates programmatically when you receive the error InvalidOperationException: Found multiple X.509 certificates.
Please Sign up or sign in to vote.
6 Feb 2011
mbcrump
Quick run through of the WP7 Developer Tools January 2011
Please Sign up or sign in to vote.
10 Feb 2011
Raymund Macaalay
Creating a Windows Service is easy, but it might be a bit tricky especially for those who are new to developing such a project.
Please Sign up or sign in to vote.
14 Feb 2011
DrABELL
Test Page for both Algorithms: http://webinfocentral.com/resources/toggleCaseAlgorithm.aspx[^]Algorithm by Robert R.: protected string ToggleCaseByRobert(string s) { var sb = new StringBuilder(s.Length); foreach (char c in s) ...
Please Sign up or sign in to vote.
11 Feb 2011
DrABELL
Interesting finding in regards to the Case Toggle Algorithm by Robert (see the following code snippet): protected string ToggleCaseByRobert(string s){ var sb = new StringBuilder(s.Length); foreach (char c in s) sb.Append(char.IsUpper(c) ? char.ToLower(c) :...
Please Sign up or sign in to vote.
15 Feb 2011
DrABELL
The computational efficiency of the Euclid's algorithm is much higher that the alternatives
Please Sign up or sign in to vote.
14 Feb 2011
hjgode
Talking with G-sensors and vector algebra. Shake and Orientation detection.
Please Sign up or sign in to vote.
17 Feb 2011
dontumindit
While dealing with databases, sometimes there is a need to get a list of tables in the application
Please Sign up or sign in to vote.
22 Feb 2011
DrABELL
Following two Toggle Case Algorithms, implemented as "pure" .NET solution (no "unsafe" coding technique, all managed code) demonstrate the best performance, tested against a variety of text strings, containing: ASCII, Unicode, all Low case, all Upper case, long numeric strings (refer to the test...
Please Sign up or sign in to vote.
1 Feb 2011
AlexCode
EF4 DbDataRecord ConvertTo
Please Sign up or sign in to vote.
6 Feb 2011
stastka
How to finde maximum Contrast of a Webcolor
Please Sign up or sign in to vote.
9 Feb 2011
Wolfgang_Baron
If you really have to put everything into a single function and want to keep the code analyzable and maybe want to be able put some common code at the end, you can always use a success variable. The code does not slow down, as the compiler optimizes the sequenced if-conditions away and produces...
Please Sign up or sign in to vote.
12 Feb 2011
SirTimothy
I use stuff like this quite often. Here's an extension, for switching quickly between two different code blocks://*doSomethingOneWay();/*/doSomethingAnotherWay();//*/As is, that will execute doSomethingOneWay(). To run doSomethingAnotherWay(), just take off the first...
Please Sign up or sign in to vote.
14 Feb 2011
dontumindit
2 alternatives  
If size of numeric array is unknown, strings can be helpful
Please Sign up or sign in to vote.
12 Feb 2011
Yaron Naveh
A command line utility to generate WCF proxies from WSDL 2.0 documents.
Please Sign up or sign in to vote.
13 Feb 2011
George Swan
You can use Linq to do the same thing double[] mydouble = str.Split('#').Select(x => double.Parse(x)).ToArray();
Please Sign up or sign in to vote.
14 Feb 2011
DrABELL
Hi everybody-There is a question posted by Rod Kemp in regards to performance benchmarks used for both algorithms (see Alternate 4). The sample code snippet, pertinent to the "ToggleCaseByJohn" algorithm is as follows: DateTime dt = DateTime.Now; for (Int64 i = 0; i
Please Sign up or sign in to vote.
17 Feb 2011
Michael B. Hansen
Couldn't resist: The following is a rewrite of Alternative 9, ToggleCaseHA()This is an unmanaged version which does direct manipulation of the input stringunsafe static string ToggleCaseUnmanaged(string str){ fixed(char* p = str) { for(int i=str.Length-1;i!=-1;--i)...
Please Sign up or sign in to vote.
19 Feb 2011
DaveAuld
Condensed single line version using one of the overloaded methods of Uri;String fullurl = new Uri(new Uri("http://website.com"), "/path/download.php").ToString();
Please Sign up or sign in to vote.
22 Feb 2011
Leom Burke
I have decided to split out the styling work into 2 posts as it would be a huge post to restyle even something so simple.
Please Sign up or sign in to vote.
1 Feb 2011
abridges
Alternate 8, why not just do this:bool bFailed = true;// In case of an exception.try{ // while bFailed while (bFailed) { // do something here. if (condition1) { // exit the loop (goto) bFalse = false; ...
Please Sign up or sign in to vote.
6 Feb 2011
User 7427435
Synchronization
Please Sign up or sign in to vote.
7 Feb 2011
Pavel Yermalovich
An example of Prototype pattern
Please Sign up or sign in to vote.
7 Feb 2011
sergiogarcianinja
As this piece of code is normally a function, should be more readable if all of it is put inside a function returning a bool, indicating success or failure.The cleanup function could be only resource deallocation, not a function at all. If it is intended to use with C++ or C#, a try..finally...
Please Sign up or sign in to vote.
7 Feb 2011
Adnan Boz
Overview: Using Claims-based Access on Windows Azure
Please Sign up or sign in to vote.
8 Feb 2011
Leom Burke
EF Code First and WPF with the Chinook database. Part 2 – The Client
Please Sign up or sign in to vote.
12 Feb 2011
Erez Zinman
Something I only found out about recently:There's a better alternative than using "cmd start...".One should use the following method:[System.Runtime.InteropServices.DllImport("shell32. dll")]private static extern long ShellExecute(Int32 hWnd, string lpOperation,string lpFile, string...
Please Sign up or sign in to vote.
12 Feb 2011
ozkary
Change Silverlight Business Application template to handle login state events
Please Sign up or sign in to vote.
12 Feb 2011
ozkary
How to create a page template on an Office Live website
Please Sign up or sign in to vote.
12 Feb 2011
ozkary
How to load JQuery to a page of an Office Live website
Please Sign up or sign in to vote.
12 Feb 2011
ozkary
How to customize the Office Live page header with an image
Please Sign up or sign in to vote.
14 Feb 2011
FZelle
You are both wrong with the DataAdapter.Why do you think there is an overload with the querystring and the connectionstring?public DataSet select_query(string query, string con_str){ try { using (SqlDataAdapter da = new SqlDataAdapter(query,con_str)) { ...
Please Sign up or sign in to vote.
14 Feb 2011
woric
The sample code provided by Andrew Rissing is a huge improvement over the original, but incorrectly catches the exception and displays a MessageBox. (Andrew correctly points out this is not a good idea.)A better solution is to allow the exception to fail:public DataSet...
Please Sign up or sign in to vote.
14 Feb 2011
Henry Minute
Sorting Lists Using an Anonymous Delegate
Please Sign up or sign in to vote.
14 Feb 2011
jim lahey
I prefer something a little more generic:public static IEnumerable Convert(string value, char separator) where TTypeConverter : TypeConverter { var typeConverter = (TTypeConverter)TypeDescriptor.GetConverter(typeof(TValue)); ...
Please Sign up or sign in to vote.
14 Feb 2011
TimB99
What about this?string s = new string(( from c in "ABCdef" select char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c) ).ToArray());Note by Alexander Bell: In regards to the performance, this one (i.e. Alternate 9) is the worst in comparison...
Please Sign up or sign in to vote.
17 Feb 2011
cechode
Using the .NET profiler, I compared ToggleCaseByRobertToggleCaseByJohnand my new one given below: static string ToggleCaseByCeChode(string s) { char[] chars = s.ToCharArray(); for (int i = 0; i
Please Sign up or sign in to vote.
15 Feb 2011
Amund Gjersøe
Visual Studio Query Builder does not work with PostgreSQL when you want to use filtering parameters. This tip show how to make your own "FillBy" methods.
Please Sign up or sign in to vote.
15 Feb 2011
UbaiSandouk
How about this:private bool IsPalindrome(string stringToCheck){ return stringToCheck.ToLower() == (new string(stringToCheck.Reverse().ToArray())).ToLower();}
Please Sign up or sign in to vote.
8 Mar 2011
Henry.Ayoola
Several of the answers here lack fallbacks for Unicode.static string ToggleCaseHA(string str) { char[] chs = str.ToCharArray(); for (int i = chs.Length - 1; i >= 0; i--) { char ch = chs[i]; char foo = (char)(ch & ~0x20); if ((foo >= 0x41 && foo
Please Sign up or sign in to vote.
16 Feb 2011
claytoC001
A simple way to determine when to execute something based on the local systems time using .NET DateTime and TimeSpan objects.

Current Participants

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

#realJSOP
Software Developer (Senior) Paddedwall Software
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.
Abhishek Sur
President
India India
Did you like his post?

Oh, lets go a bit further to know him better.
Visit his Website : www.abhisheksur.com to know more about Abhishek.

Abhishek also authored a book on .NET 4.5 Features and recommends you to read it, you will learn a lot from it.
http://bit.ly/EXPERTCookBook

Basically he is from India, who loves to explore the .NET world. He loves to code and in his leisure you always find him talking about technical stuffs.

Working as a VP product of APPSeCONNECT, an integration platform of future, he does all sort of innovation around the product.

Have any problem? Write to him in his Forum.

You can also mail him directly to abhi2434@yahoo.com

Want a Coder like him for your project?
Drop him a mail to contact@abhisheksur.com

Visit His Blog

Dotnet Tricks and Tips



Dont forget to vote or share your comments about his Writing
abridges
Web Developer
United States United States
No Biography provided
Adnan Boz
United States United States
I am an MCAD, MCSD, MCTS, MCPD, MCT and Certified CUDA Programmer.
You can find more technical articles on my blog at http://www.adnanboz.com.
AlexCode
Architect
Switzerland Switzerland
Senior IT Consultant working in Switzerland as Senior Software Engineer.

Find more at on my blog.
Amund Gjersøe
Engineer
Norway Norway
No Biography provided
Brij
Software Developer (Senior)
India India
Brij is a 3-times Microsoft MVP in ASP.NET/IIS Category and a passionate .NET developer. More than 6 years of experience in IT field, currently serving a MNC as a Tech Lead/Architect.

He is a very passionate .NET developer and have expertise over Web technologies like ASP.NET 2.0/3.5/4.0, jQuery, JSON, Javascript, IIS and related technologies. He is also a Exchange Server (EWS) Specialist. He has great experience in design patterns and N-Tier Architecture.

He is also certified as Microsoft Certified Technologies Specialist-ASP.NET and Microsoft Certified Technologies Specialist-WCF in .NET 4.0. He has also received several awards at various forums and his various articles got listed as "Article of the day" at ASP.NET Microsoft Official Website www.asp.net.

He has done MCA from NIT Durgapur and completed his graduation from Lucknow University.

Learning new technologies and sharing knowledge excites him most. Blogging, solving problems at various forums, helping people, keeps him busy entire day.


Visit his Blog: Code Wala

Area of Expertise :
C#, ASP.NET 2.0,3.5,4.0, AJAX, JQuery, JSON, XML, XSLT, ADO.Net, WCF, Active Directory, Exchange Server 2007 (EWS), Java script, Web Services ,Win services, DotnetNuke, WSS 3.0,Sharepoint Designer, SQL Server 2000/2005/2008
cechode
United States United States
No Biography provided
claytoC001
Systems Engineer
United States United States
No Biography provided
DaveAuld
Engineer
Scotland Scotland
I have been working in the Oil & Gas Industry for over 30 years now.

Core Discipline is Instrumentation and Control Systems.

Completed Bsc Honours Degree (B29 in Computing) with the Open University in 2012.

Currently, Offshore Installation Manager in the Al Shaheen oil field, which is located off the coast of Qatar. Prior to this, 25 years of North Sea Oil & Gas experience.
dontumindit
Pakistan Pakistan
I am a learner.
DrABELL
Software Developer (Senior)
United States United States
Dr. Alexander Bell is a seasoned full-stack Software Engineer (Win/Web/Mobile). He holds PhD in Electrical and Computer Engineering, authored 37 inventions and published 300+ technical articles. Currently focused on multiple Android/Mobile development projects and Big Data' Machine Learning, AI, IoT. Alex participated in App Innovation Contests (AIC 2102/2013) with multiple winning submissions. Sample portfolio apps and publications:

  1. Publications by A. Bell
  2. Educational Web Portal
  3. Engineering Calculator VOLTA
  4. Aggregate Product function extends SQL
  5. Use SQL to generate large data sequence
  6. HTML5/CSS3 graphic enhancement: buttons, inputs
  7. Advanced CSS3 Styling of HTML5 SELECT Element
  8. enRoute: Real-time NY City Bus Tracking Web App
  9. YouTube™ API for ASP.NET
  10. HTML5 Tables Formatting: Alternate Rows, Color Gradients, Shadows
Erez Zinman
United States United States
No Biography provided
FZelle
Web Developer
Germany Germany
Software-Developer since 1990
Specialiced in LAN/WAN Tracers ( sniffer )
now developing in .NET ( c#, VB, ASP ..)
George Swan
Student
Wales Wales
No Biography provided
Henry Minute
Retired
United Kingdom United Kingdom
Retired Systems Admin, Programmer, Dogsbody.
Mainly on Systems for Local Government, Health Authorities,
Insurance Industry - (COBOL eeeeeeeugh).
Inventor of Synchronized Shopping.
Henry.Ayoola
United States United States
No Biography provided
hjgode
Germany Germany
No Biography provided
Inaki Ayucar
Software Developer (Senior)
Spain Spain
Inaki Ayucar is a Microsoft MVP in DirectX/XNA, and a software engineer involved in development since his first Spectrum 48k, in the year 1987. He is the founder and chief developer of The Simax Project (www.simaxvirt.com) and is very interested in DirectX/XNA, physics, game development, simulation, C++ and C#.

His blog is: http://graphicdna.blogspot.com

To contact Inaki: iayucar@simax.es
jasonalls
Software Developer Lucid Research Limited
United Kingdom United Kingdom
I have been programming software since 1999. My qualifications include CIW Associate, SCJP for the Java 1.4 Platform, MCAD using Visual C#, and PRINCE2 Practitioner.
jim lahey
Software Developer (Senior)
United Kingdom United Kingdom
First batch file in 1987

Messed around with the Bullfrog C++ Libraries for Syndicate in 1994

Web Developer since 2000

.net Developer since 2001

MCTS: Microsoft® .NET Framework 2.0 - Web-based Client Development

MCTS: Web Applications Development with Microsoft .NET Framework 4
Leom Burke
Software Developer (Senior)
United Kingdom United Kingdom
I am a developer currently working for a financial company in the UK with a focus on back end work using NServiceBus. Personally I also enjoy working with ASP.NET (MVC), WPF, ruby and investigating best practice using methods like TDD and bettering the quality of code.
mbcrump
Software Developer (Senior) Telerik
United States United States
Michael Crump is a Silverlight MVP and MCPD that has been involved with computers in one way or another for as long as he can remember, but started professionally in 2002. After spending years working as a systems administrator/tech support analyst, Michael branched out and started developing internal utilities that automated repetitive tasks and freed up full-time employees. From there, he was offered a job working at McKesson corporation and has been working with some form of .NET and VB/C# since 2003.

He has worked at Fortune 500 companies where he gained experience in embedded systems design and software development to systems administration and database programming, and everything in between.

His primary focus right now is developing healthcare software solutions using Microsoft .NET technologies. He prefers building infrastructure components, reusable shared libraries and helping companies define, develop and automate process standards and guidelines.

You can read his blog at: MichaelCrump.net or follow him on Twitter at @mbcrump.
Michael B. Hansen
Founder CWAIN
Denmark Denmark
I have a MCPD .NET 3.5 EAD and a Bsc in computer science, organizational theory and economics.
After more than 15 years working as professional system engineer, I founded the independent consultant agency CWAIN.
OriginalGriff
CEO
Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?
ozkary
Architect OG-BITechnologies
United States United States
Software engineer, author & speaker who enjoys mentoring, learning, speaking and sharing with others about software development technologies. Microsoft MVP.

My Blog
Pavel Yermalovich
Software Developer (Senior)
Belarus Belarus
Software developer with over 3 years of extensive experience in analysis, design and development. Recently, most interested in refactoring and design patterns applied to .NET Framework.

Core technologies I am using: OOP, OOD, DDD, TDD, N-tier applications, enterprise development.

Certificates:
Brainbench: .NET Framework 3.5 Fundamentals, Data Modeling Concepts, Web Design Concepts, C#

Microsoft: Exam 70-526: TS: Microsoft .NET Framework 2.0 - Windows-Based Client Development

INTUIT.RU: Development of Web-application ASP. NET Using Visual Studio. NET, Web applications in ASP.NET, Microsoft .NET Framework Distributed Applications Development.

Specialties
NET Framework : 2.0, 3.5, 4.0
Languages and technologies: C#, ASP.NET MVC 2, ASP.NET MVC 3, WCF, ASP.NET 4.0, Web Services, ADO.NET, LINQ, Entity Framework, NHibernate 3.0, JavaScript, HTML, CSS, XML, Ajax
RDBMS : SQL Server 2005, 2008, 2008 R2, MS Access.
Reporting: MS SQL Reporting Services, Crystal Reports
Raymund Macaalay
Technical Lead
New Zealand New Zealand
http://nz.linkedin.com/in/macaalay
http://macaalay.com/
Robert Rohde
Web Developer
Germany Germany
No Biography provided
Sandeepkumar Ramani
Technical Lead
India India
I write software using Microsoft web technologies since 2008. I have successfully delivered software products for Fortune 500 companies and startups.

Microsoft Certified Technologies Specialist - Web Applications Development with Microsoft .NET Framework 4.

Awarded as Microsoft Community Contributor of the year 2011.

Received several awards at various forums and my various articles got listed as "Article of the day" at ASP.NET Microsoft Official Website https://www.asp.net/

Visit My Blog:
https://ramanisandeep.wordpress.com/


Area of Expertise:
C#, ASP.NET, Web Services, WCF, ASP.NET MVC, SQL Server, WEB API, AngularJS, jQuery
No Biography provided
Shailendra P Singh
Software Developer
India India
I am a Microsoft technology enthusiast having experience on various flavors of Microsoft Technologies which includes ASP.Net, Winforms to Silverlight, WPF.

I hold MCTS Certification on .Net 2.0 and Silverlight 4.0
SirTimothy
United States United States
No Biography provided
stastka
Web Developer
Switzerland Switzerland
No Biography provided
TimB99
Software Developer
New Zealand New Zealand
No Biography provided
UbaiSandouk
United States United States
No Biography provided
User 7427435
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided
Wolfgang_Baron
Technical Lead private interest
Germany Germany
No Biography provided
woric
Web Developer
Australia Australia
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Yaron Naveh
Software Developer (Senior)
Israel Israel
Web services interoperability expert.

http://webservices20.blogspot.com/
You must sign in to participate in this contest.
This contest has ended.
1 Feb - 28 Feb 2011