DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Getting Started With the YugabyteDB Managed REST API
  • Creating Scalable OpenAI GPT Applications in Java
  • Zero Trust Network for Microservices With Istio
  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations

Code refactoring with Visual Studio 2010 Part-1

Jalpesh Vadgama user avatar by
Jalpesh Vadgama
·
Jun. 26, 11 · News
Like (0)
Save
Tweet
Share
4.57K Views

Join the DZone community and get the full member experience.

Join For Free

Visual Studio 2010 is a Great IDE(Integrated Development Environment) and we all are using it in day by day for our coding purpose. There are many great features provided by Visual Studio 2010 and Today I am going to show one of great feature called for code refactoring. This feature is one of the most unappreciated features of Visual Studio 2010 as lots of people still not using that and doing stuff manfully. So to explain feature let’s create a simple console application which will print first name and last name like following.

ConsoleApplication

And following is code for that.

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

So as you can see this is a very basic console application and let’s run it to see output.

Output

So now lets explore our first feature called extract method in visual studio you can also do that via refractor menu like following. Just select the code for which you want to extract method and then click refractor menu and then click extract method. Now I am selecting three lines of code and clicking on refactor –> Extract Method just like following.

ExtractMethod

Once you click menu a dialog box will appear like following.

ExtractMethodDialog

As you can I have highlighted two thing first is Method Name where I put Print as Method Name and another one Preview method signature where its smart enough to extract parameter also as We have just selected three lines with console.writeline. One you click ok it will extract the method and you code will be like this.

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

So as you can see in above code its has created a static method called Print and also passed parameter for as firstname and lastname. Isn’t that great!!!. It has also created static print method as I am calling it from static void main. Hope you liked it.. Stay tuned for more..Till that Happy programming.

Published at DZone with permission of Jalpesh Vadgama, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Getting Started With the YugabyteDB Managed REST API
  • Creating Scalable OpenAI GPT Applications in Java
  • Zero Trust Network for Microservices With Istio
  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: