---
# System prepended metadata

title: 'How to: Group and Sort Properties with Backing Fields'

---

# How to: Group and Sort Properties with Backing Fields 

[Organize Members](xref:116041) can group and sort properties with backing fields with the following criteria:

* [Keep backing fields with their corresponding properties](#keep-backing-fields-with-their-corresponding-properties).
* [Group properties with backing fields by visibility](#group-properties-with-backing-fields-by-visibility).

This example describes how to create, configure, and apply rules for properties with backing fields to implement scenarios described above. 

## Keep Backing Fields with their Corresponding Properties

1.  Open the **Editor** | **All Languages** | **Organize Members** [options](xref:115925) page to configure the Organize Members. 
  
    ![](https://i.imgur.com/OgqYKUP.png)
    

2. Choose the **StyleCop** rule set in the "Rule set" section.  
 
   ![](https://i.imgur.com/9J4Iezu.png)   
   

3. Select the "Properties" rule.

   ![](https://i.imgur.com/PJ7y9xD.png)
   

   You can change the name for this rule (optional). In this example, leave the rule name as is. 
   
4. Change the "Properties" rule settings. 

   Set the [Rule priority](xref:118795#rule-priority) option to **High priority** to group backing fields with their properties prior to other rules. 

   Configure grouping and sorting as shown in the screenshot below: 

   ![](https://i.imgur.com/4eF0Q5G.png)   
   

   For information on how to use the filter editor in the "Group by" section, refer to the following example: [How to: Create a Rule](xref:401398).

5. Click **Apply** and **OK** to save the changes and close the **Organize Members** options page.

6. Copy the following code and paste it to your project. 

   # [C#](#tab/tabid-csharp)
	
   ```csharp
   namespace Proj
   {
       public class Sample
       {
           string fieldA;
           int fieldB;
           string fieldC;
           int fieldD;
           string fieldE;
           public string PropertyA {
               get {
                   return fieldA;
               }
               set {
                   fieldA = value;
               }
           }
           internal int PropertyB {
               get {
                   return fieldB;
               }
               set {
                   fieldB = value;
               }
           }
           public string PropertyC {
               get {
                   return fieldC;
               }
               set {
                   fieldC = value;
               }
           }
       }
   }
   ```
   ***

7. Run [Organize members](xref:116041). 

   Place the caret in a class member in the code above, press **Ctrl + .** or **Ctrl + ~** to invoke the **Code Actions** menu, select **Organize Members**, and press **Enter**.
   
   ![](https://i.imgur.com/OWj3pyJ.gif)
   

CodeRush places backing fields with their corresponding properties.


## Group Properties with Backing Fields by Visibility

1. Open the [Organize Members](xref:116041) options page. See the step 1 in the previous section. 

2. Select the "Internal properties" rule in the "Default" rule set.   

   ![](https://i.imgur.com/YyxBAEs.png)   
   
    
    You can change the name for this rule (optional). In this example, leave this rule name as is.   

3. Change the "Internal properties" rule settings as shown in the screenshot below. 

    ![](https://i.imgur.com/MkBq7VY.png)
    

4. Select the "Public properties" rule and change its settings similarly. The modified rule looks as follows: 

    ![](https://i.imgur.com/TxBvEJI.png)
   

5. Click **Apply** and **OK** to save the changes and close the **Organize Members** options page.

6. Copy the code from the previous section (see the step 6) and paste it to your project. 

7. Run [Organize members](xref:116041).

   Place the caret in a class member in the code above, press **Ctrl + .** or **Ctrl + ~** to invoke the **Code Actions** menu, select **Organize Members**, and press **Enter**.
   
   ![](https://i.imgur.com/0B2N9cd.gif)   

CodeRush places backing fields with their corresponding properties by visibility.