Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharp_Prog_Guide.doc
Скачиваний:
16
Добавлен:
16.11.2019
Размер:
6.22 Mб
Скачать

Заметки

Эта операция оптимизации лучше всего действует в том случае, когда превращаемой переменной присваивается постоянное значение. Переменная должна объявляться и инициализироваться, это не должно быть только объявление или только присвоение значения.

How to: Promote Local Variable to Parameter

Use this procedure to perform the Promote Local Variable to Parameter refactoring operation.

To promote a local variable to parameter

  1. Create a console application, and set it up as described in the following example.

  2. Place the pointer next to i at its definition in MethodB.

  3. From the Refactor menu, select Promote Local Variable to Parameter.

You can also type the keyboard shortcut CTRL+R, P to complete the refactoring operation.

You can also right-click the pointer, point to Refactor on the context menu, and then click Promote Local Variable to Parameter to complete the refactoring operation.

The MethodB should now have a parameter int i, and the call ProtoA.MethodB will now pass zero as a value.

Example

To set up this example, create a console application named PromoteLocal, and then add the following code after the Program class in the PromoteLocal namespace.

class ProtoA

{

public static void MethodB()

{

// Invoke on 'i'

int i = 0;

}

}

class ProtoC

{

void MethodD()

{

ProtoA.MethodB();

}

}

Превращение локальной переменной в параметр

Эта процедура используется для выполнения операции оптимизации "Превращение локальной переменной в параметр".

Чтобы выполнить превращение локальной переменной в параметр

  1. Создайте консольное приложение и настройте его, как показано в следующем примере.

  2. Расположите курсор около переменной i в месте ее определения в методе MethodB.

  3. В меню Оптимизация выберите пункт Превращение локальной переменной в параметр.

Кроме того, для выполнения операции оптимизации можно нажать сочетание клавиш CTRL+R, P.

Также для выполнения операции оптимизации можно щелкнуть правой кнопкой мыши курсор, выбрать пункт контекстного меню Оптимизация и затем щелкнуть Превращение локальной переменной в параметр.

Теперь метод MethodB должен иметь параметр int i, а вызов метода ProtoA.MethodB теперь будет передавать zero как значение.

Пример

Для подготовки этого примера создайте консольное приложение с именем PromoteLocal и затем добавьте следующий код после класса Program в пространстве имен PromoteLocal.

-----------

Code Colorization

The code editor parses tokens and code constructs so they are easily recognizable and distinguishable from other code content in the code editor. After the code editor parses your code, it colorizes code constructs appropriately.

Tokens

The code editor colorizes the following token types.

  • Comment

  • Excluded Code

  • Identifier

  • Keyword

  • Number

  • Operator

  • Preprocessor Keyword

  • String

  • String (C# @ Verbatim)

  • User Types

  • User Types (Value Types)

  • User Types (Enums)

  • User Types (Delegates)

  • XML CData Section

  • XML Doc Attribute

  • XML Doc Comment

  • XML Doc Tag

You can modify the default colorization setting by using the Fonts and Colors, Environment, Options Dialog Box.