Variant data type equivalent to C#'s

John 506 Reputation points
2023-06-17T18:38:01.21+00:00

What is the equivalent of VBA's variant data type for C#?

Microsoft 365 and Office | Development | Other
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,766 Reputation points Volunteer Moderator
    2023-06-18T23:39:08.64+00:00

    the object datatype is the closest to the vb variant.

    // explicit
    object a = 10; // int (boxed)
    a = "abc";     // now string
    
    // var
    var b = new object();
    b = 10;        // now int (boxed)
    b = "abc";     // now string
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.