Useful C# CodeSnippets for VS2005

For any reason VS 2005, doesn't ship with code snippets for C#, although it does for Visual Basic. There is a huge package of useful snippets ready for download on MS's Visual Studio page: Visual Studio 2005: Visual Studio 2005 Code Snippet

codesnippet.gif

E.g. inserting the code snippet "Search a Directory for a file recursively" inserts this code to your class file:

System.Collections.ArrayList files = new System.Collections.ArrayList();
 DirSearch(@"C:",ref files);
//Method to Search Directory for specified file Type.Paste it outside the function
public void DirSearch(string sDir,ref System.Collections.ArrayList files)
{
	 try
	{
	   foreach (string d in System.IO.Directory.GetDirectories(sDir))
	   {
		foreach (string f in System.IO.Directory.GetFiles(d, "*.txt"))
		{
		   files.Add(f);
		}
		DirSearch(d,ref files);
	   }
	}
	catch (System.Exception excpt)
	{
		Console.WriteLine(excpt.Message);
	}
}
Advertisements
Published in: on May 21, 2006 at 9:41 am  Leave a Comment  

The URI to TrackBack this entry is: https://codepoetry.wordpress.com/2006/05/21/useful-c-codesnippets-for-vs2005/trackback/

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: