Variant Type Inference in Business Central
Published on 2025-06-27
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'?
var
v: Variant;
begin
v := 'Variant';
end;
a) IsText = true
b) IsChar = true
c) IsCode = true
- What type is inferred into the Variant variable when assigned a value of 'CODE'?
var
v: Variant;
begin
v := 'CODE';
end;
a) IsText = true
b) IsChar = true
c) IsCode = true
- What type is inferred into the Variant variable when assigned a value of '1'?
var
v: Variant;
begin
v := '1';
end;
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.