Visual Studio, Code Search

Plus

Sometimes code snippets are handy. A Visual Studio add-in released by Microsoft Research allows you to type what you want a piece of code to do. And a selection of code fragments are provided from Internet sources.

Example

Let us try an example. We want to reverse the characters in a string here. So in Visual Studio (or the example site) try adding a comment describing this action. I used "///reverse string value" and pressed tab.

Bing Code Search: Microsoft ResearchString

Then:I browsed the resulting code snippets.
I selected some code from Dot Net Perls.
And the code was inserted.

Finally:I ran the program in Visual Studio (after some small changes). The word "carrot" was correctly reversed.

Reverse String
Example step 1: C#

using System;

namespace Demo
{
    class Program00
    {
	static void Method01(string[] args)
	{
	    string value = "carrot";
	    ///reverse string value
	}
    }
}

Example step 2: C#

using System;

namespace Demo
{
    class Program00
    {
	static void Method01(string[] args)
	{
	    string value = "carrot";
	    ///reverse string value
	    char[] arr = value.ToCharArray();
	    Array.Reverse(arr);              
	    var result = new string(arr);    
	}
    }
}

Completed program: C#

using System;

class Program
{
    static void Main()
    {
	string value = "carrot";
	///reverse string value
	char[] arr = value.ToCharArray();
	Array.Reverse(arr);
	var result = new string(arr);
	Console.WriteLine(result);
    }
}

Output

torrac

Discussion

C# language

Usually, I recommend reading about code and trying to understand what it does, and how it works. But code snippets have their place, and I use them sometimes too. This add-in is an alternative to using a search engine to locate snippets.

Also:The add-in lets you visit the website where the code snippet was found, so you can do further research that way.

Summary

Copyright

This tool can be useful for learning C#: it lets you quickly browse and compare code with no distractions. It is not a substitute for researching the ideas behind code, but it is an extension (an add-in) to the experience.


C#: .NET: VS