Home Page
"Join my free Amazing ASP.NET newsletter"
It's safe and easy to signup. You get:
  • Notified anytime a new article comes out
  • Technical step-by-step tutorials on all important ASP.NET topics
  • Expert guidance so you can reach unlimited ASP.NET success
  • Important ASP.NET news updates
Enter your Email

When you are coding in C#, there may be many times where you give a name to a class or a method and you decide later that you want to change that name.  This is especially true for objects that have a default name like the “_Default” class that is autogenerated for the Default.aspx web form when you create a brand new web site in Visual Web Developer.  In this lesson I will cover an easy way to rename a class or a method and have the Visual Web Developer IDE handle changing the name throughout the entire program automatically for me.

In order to rename a class and have the IDE change all the code in the program that references the old name to refer to the new name, I can use the refactor feature.  It is very easy to use and is accessible by right clicking over the object that you want to rename.  When you right click over a class name for example, you then choose Refactor->Rename.  A rename popup dialog box will appear.  Type in the new name for the class and click “Preview reference changes”.  Preview is a good idea because it will give you an idea of how many lines of code in your program the IDE will automatically update for you with the new name of the class.  Click OK and the Preview Changes window will appear showing you all the places that will be changed in the program.  Click Apply to perform the refactoring.  You can use this feature with method names and variable names as well. 

It is important to use this refactor feature rather than just change the name of the objects manually yourself, because if you make manual changes, you may not realize how many places in your program are referencing the object being renamed.  Click here to see an example video where I change the name of a class using the refactor feature of Visual Web Developer.

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment