Variant Type Inference in Business Central
What happens when you use the Variant data type in Business Central and assign different values?
Quiz
- 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
- 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
- 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
- a)
- a)
- 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.