António's DevLog

Variant Type Inference in Business Central

What happens when you use the Variant data type in Business Central and assign different values?

Quiz

  1. What type is inferred into the Variant variable when assigned a value of ‘Variant’?
1var
2  v: Variant;
3begin
4  v := 'Variant';
5end;

a) IsText = true

b) IsChar = true

c) IsCode = true

  1. What type is inferred into the Variant variable when assigned a value of ‘CODE’?
1var
2  v: Variant;
3begin
4  v := 'CODE';
5end;

a) IsText = true

b) IsChar = true

c) IsCode = true

  1. What type is inferred into the Variant variable when assigned a value of ‘1’?
1var
2  v: Variant;
3begin
4  v := '1';
5end;

a) IsText = true

b) IsChar = true

c) IsCode = true

Answers

  1. a)
  2. a)
  3. c)

It is good to understand that in text based types - Char, Code and Text - the only possible inference will be Char and Text, because Code follows a different rule set that cannot be ensured by just providing a string literal to a variable, unlike Char and Text which only differ in size.

<< Previous Post

|

Next Post >>