Skip to main content

Initialize

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).

    public string GetDefaultValue() {
        string str
        Console.WriteLine("Default value is {0}", str);
        return str;
    }
    
  2. Press Ctrl + . or Ctrl + ~ to invoke the Code Actions Menu, select Initialize from the menu and press Enter.

    Initialize

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

public string GetDefaultValue() {
    string str = string.Empty;
    Console.WriteLine("Default value is {0}", str);
    return str;
}