User Id :    Password :      New Member   Forgot Password  
 
Code refactoring in C# with Visual Studio 2010-Part 3
Description Code refactoring in C# with Visual Studio 2010-Part 3   No. of Views     1741
  Rating     5
Author Jalpesh Vadgama   Posted On     21 Jul 2011
Tags C# 4.0,Code Refactor,Visual Studio 2010    

Sample Code   Download Code

 

I have been writing few post about Code refactoring features of visual studio 2010 and This blog post is also one of them. In this post I am going to show you reorder parameters features in visual studio 2010. As a developer you might need to reorder parameter of a method or procedure in code for better readability of the the code and if you do this task manually then it is tedious job to do. But Visual Studio Reorder Parameter code refactoring feature can do this stuff within a minute. So let’s see how its works. For this I have created a simple console application which I have used earlier posts . Following is a code for that.

 

using System;
 
namespace CodeRefractoring
{
  class Program
  {
      static void Main(string[] args)
      {
          string firstName = "Jalpesh";
          string lastName = "Vadgama";
 
          PrintMyName(firstName, lastName);
      }
 
      private static void PrintMyName(string firstName, string lastName)
      {
          Console.WriteLine(string.Format("FirstName:{0}", firstName));
          Console.WriteLine(string.Format("LastName:{0}", lastName));
          Console.ReadLine();
      }
  }
}

 

Above code is very simple. It just print a firstname and lastname via PrintMyName method. Now I want to reorder the firstname and lastname parameter of PrintMyName. So for that first I have to select method and then click Refactor Menu-> Reorder parameters like following.

 

 

Once you click a dialog box appears like following where it will give options to move parameter with arrow navigation like following.

 

 

Now I am moving lastname parameter as first parameter like following.

 

 

Once you click OK it will show a preview option where I can see the effects of changes like following.

 

Once I clicked Apply my code will be changed like following.

using System;
 
namespace CodeRefractoring
{
  class Program
  {
      static void Main(string[] args)
      {
          string firstName = "Jalpesh";
          string lastName = "Vadgama";
 
          PrintMyName(lastName, firstName);
      }
 
      private static void PrintMyName(string lastName, string firstName)
      {
          Console.WriteLine(string.Format("FirstName:{0}", firstName));
          Console.WriteLine(string.Format("LastName:{0}", lastName));
          Console.ReadLine();
      }
  }
}

 

As you can see its very easy to use this feature. Hoped you liked it.. Stay tuned for more.. Till that happy programming.

 

 

About Author

About Author I am jalpesh vadgama an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 5 years of experience in .NET Technology.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible. Please also visit my blog at http://jalpesh.blogspot.com/ Jalpesh Vadgama
No Photo
 
Country India
Company N/A
Home Page http://jalpesh.blogspot.com/

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

 
 
Posted By Gaurav on 03 Aug 2011 at 05:28 AM
 
Very good feature
 
 
   
Write your comment here.
Comment
Verification Code