Back to Devexpress

Initialize

coderushforroslyn-400684-coding-assistance-code-providers-initialize.md

latest1.1 KB
Original Source

Initialize

  • Aug 19, 2021

Purpose

The Initialize code provider initializes the variable or the field with the default type value.

Availability

Available when the caret is on an initialization statement, and the initialization value is not specified.

Note

This code provider is available in C# and Visual Basic code.

How to Use

  1. Place the caret on a variable or field (“str” in this example).

  2. Press Ctrl + . or Ctrl + ~ to invoke the Code Actions Menu , select Initialize from the menu and press Enter.

After execution, the Code Provider initializes the variable or the field with the default type value.

csharp
public string GetDefaultValue() {
    string str = string.Empty;
    Console.WriteLine("Default value is {0}", str);
    return str;
}
vb
Public Function GetDefaultValue() As String
    Dim str As String = String.Empty
    Console.WriteLine("Default value is {0}", str)
    Return str
End Function