anytype in x++ Programming Language

Rumman Ansari   Software Engineer   2023-08-23   1095 Share
☰ Table of Contents

Table of Content:


anytype in x++ Programming Language

The anytype data type is a placeholder for any data type. You should use variables of this type only as arguments and return values.

To use anytype as a variable, you must first assign a value to it, otherwise, a run-time error occurs. After you've assigned a value to anytype, you can't convert it to another data type.

Although you can use anytype variables in expressions, they're usually used as arguments and return types. The size, precision, scope, default value, and range of anytype depend on the conversion type that you assign to it. You can use anytype just as you use the data type that you convert it to. For example, if you assign an integer, you can then apply relational and arithmetic operators to the variable.

An anytype variable is automatically converted to a date, enumeration (enum), integer, real, string, extended data type (EDT) (record), class, or container when a value is assigned to the type. Additionally, the following explicit conversion functions can be used: any2dateany2enumany2intany2real, and any2str. You can't change the variable to another data type after you've converted it to anytype.


Example anytype in x++ Programming Language


// An example of using anytype variables.
public static str range(anytype _from, anytype _to)
{
    return queryValue(_from) + '..' + queryValue(_to);
}

// Another example of using anytype variables.
void put(int position, anytype data)
{
    record = conPoke (record, position, data);
}

public void AnytypeMethod()
{
    // An example of automatic conversion for anytype.
    anytype a;
    a = "text"; // Automatically assigns a string literal.
}