Initialize

The Initialize code provider initializes the variable or the field under the caret with the default type value. You can specify the default type values used for initialization via the Type Initializers options page.

Availability

From the context menus or via shortcuts, when the edit cursor or caret is on an initialization statement, provided that the initialization value is not specified.

Example

Note

The following example will work if you specify the appropriate initializer values for the string type on the Type Initializers options page.

StringTypeInitializers

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

Result:

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

Screenshot

Initialize