C#
  Home arrow C# arrow C# Tips: Keep it Short, Get it Done
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

C# Tips: Keep it Short, Get it Done
By: David Fells
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 24
    2006-01-30

    Table of Contents:
  • C# Tips: Keep it Short, Get it Done
  • Implementing IDisposable
  • Using “using”
  • Using “as” and “is"

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    C# Tips: Keep it Short, Get it Done


    (Page 1 of 4 )

    If your goal is to write the most effective code possible, you will want to read this article. David Fells discusses three often-neglected C# language constructs that help you write as few lines of code as possible to accomplish your tasks.

    Introduction

    Developers today have a fairly generous selection of object oriented languages to choose from, and most developers end up learning more than one of them at one time or another. As a result, a lot of developers never learn about the lower level workings of those languages. The .NET runtime and its innards are well beyond the scope and purpose of this article. In fact, this article assumes that readers know the basics of how IL is generated and run.

    One of the beauties of modern languages like C# is that developers no longer have to worry about memory management and garbage collection. This does not, however, mean that developers should ignore them and become complacent – we should always strive to write the most effective code possible. When I say effective, what I am referring to is this: writing the fewest lines of code possible while utilizing the built in language features to complete a task.

    In this article we are going to examine three C# language constructs that are, in my observations, neglected by most developers. We will first look at the “using” statement, which provides a form of “try/catch” structure with improved garbage disposal. In conjunction with the “using” statement we will take a look at the standard “Dispose” pattern (implementing the “IDisposable” interface) We will examine the other two constructs, “is” and “as”, together. The “is” keyword provides a native mechanism for learning an object’s type, and “as” provides a safe, concise type cast.

    More C# Articles
    More By David Fells


       · Hello! Thanks for checking out my article. Your comments and feedback are welcome,...
       · One important tip: Don't overuse the "as" operator.For example, if myObject is...
     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT