Tips & Tricks: Rectangular selection of code in Visual Studio

Introduction:

"Rectangular selection of code" is feature which is given by Microsft in Visual Studio IDE.

Example:

Assume we have Employee class as shown below:

public class Employee
{
    public int EmployeeID { get; set; }
    public string EmployeeName { get; set; }
    public string Address { get; set; }
}

Now my requirement is to change all properties to private. How we will do normally? We will go to each property and we will change it to private. This is fine for one or two properties. But if we have 20 properties in our class, then going to each property and doing modifications will take time. How we can do this in a simple way? To do this kind of modifications in visual studio, we have a feature called "Rectangular Selection". Now we will see this in step by step:

In the above figure shows some directions to select the public keywords. We will select all public keywords by holding the Alt key and then start selection from left top to bottom right of public keywords as shown in below figures.

Press Alt keyword, hold it and start selction(by using mouse) of public keyword, then move the cursor towards down to select all the keywords.

Note: If you want do selection by using keyboard, then use shift + Alt and Left, Right, Down, and Up keys.

Now start typing private. Then all public keywords will be replaced with private. See the sample screen shots below:

If you observe the above figure, while typing only all the keywords are replced. In the below figure you will see the final output.

Thats it. I hope you enjoyed this article. We will add more articles on "Tips & Tricks" in the coming days.

  • Created
    Mar 26, 2015
  • Updated
    Mar 27, 2015
  • Views
    281