string

Type Default Value
string "" (empty string)

The string type represents text via a sequence of characters.

Auto-boxing

All primitive types have a corresponding wrapper class. The corresponding wrapper class for the string type is System.String.

Auto-boxing occurs when a value of a primitive type is assigned or passed as an argument to a variable or function that expects a value of its corresponding wrapper class. For example, the string value "abc" would fit within a string and can be assigned to a variable of type System.String via auto-boxing:

1
System.String value = "abc"; // Auto-boxing

Without auto-boxing, the equivalent code would be:

1
System.String value = new System.String("abc");

The reverse also occurs. Unboxing is when the wrapper class is automatically converted to its corresponding primitive type. Thus, an instance of System.String can be unboxed to the string primitive type.

1
string value = new System.String("abc"); // Unboxing

Conversions for Internal Types

For conversions to and from the string type, consult the Conversions Table.

Conversions for external Type

When converting from external:

  • If the external value is a numeric value (including zero), it will be automatically converted to its string equivalent. For example, 123 is converted to "123".

  • If the external value is NaN, it will be automatically converted to an empty string. Unimplemented

  • If the external value is positive or negative Infinity, it will be automatically converted to "Infinity" and "-Infinity", respectively.

  • If the external value is a string value, it will retain its current value.

  • If the external value is the Boolean true value, it will be automatically converted to "true".

  • If the external value is the Boolean false value, it will be automatically converted to "false".

  • If the external value is null or undefined, it will be automatically converted to an empty string.

  • If the external value is an array, it will be automatically converted to an empty string (due to conversion failure). Unimplemented

  • If the external value is an object, it will be automatically converted to an empty string (due to conversion failure). Unimplemented

  • If the external value is an function, it will be automatically converted to an empty string (due to conversion failure). Unimplemented

When converting to external, the value will be converted to a JavaScript string value.

See Also

Share

HTML | BBCode | Direct Link